Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 78072

IWorkbookExporter?

$
0
0
I found the information on a blog.  Your documentation needs to be more thorough and should require an additional link to a blog.  I am now getting an error I need your insight to resolve.  I cannot attach an .xlsx file to this forum so you need to give me some tools to get you the file that errors.

 

I use this code to import from a file:

Microsoft.Win32.SaveFileDialog dlg =
    newMicrosoft.Win32.SaveFileDialog();
 
dlg.DefaultExt = ".xlsx";
dlg.Filter = "Excel | *.xlsx";
dlg.Title = "Identify Location";
dlg.InitialDirectory =
    Environment.GetFolderPath(Environment.SpecialFolder.Desktop);                
 
dlg.CheckFileExists = false;
dlg.CheckPathExists = true;
dlg.FilterIndex = 2;
dlg.RestoreDirectory = true;
  
bool? dlgRst = dlg.ShowDialog();
 
if(dlgRst == true)
{
    FileInfo file =
        newFileInfo(dlg.FileName);
  
    XlsxFormatProvider provider =
        newXlsxFormatProvider();
 
    using(Stream stream = newFileStream(file.FullName, FileMode.CreateNew, FileAccess.Write))
    {
        provider.Export(reportExcelControl.Workbook, stream);
    }
}

 

However, the import action corrupts the file... it can no longer be opened in Excel and its size changes to 0:

Telerik.Windows.Zip.InvalidDataException: Archive corrupted ---> System.IO.IOException: An attempt was made to move the file pointer before the beginning of the file.
 
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.SeekCore(Int64 offset, SeekOrigin origin)
   at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)
   at Telerik.Windows.Zip.ZipArchive.ReadEndOfCentralDirectory()
   --- End of inner exception stack trace ---
   at Telerik.Windows.Zip.ZipArchive.ReadEndOfCentralDirectory()
   at Telerik.Windows.Zip.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)
   at Telerik.Windows.Zip.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding, CompressionSettings compressionSettings, EncryptionSettings encryptionSettings)
   at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ImportOverride(Stream input)
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.WorkbookFormatProviderBase.Import(Stream input)
   at Hpt.Product.Measurement.UC.MeasurementReportUC.btnImportFromFile_Click(Object sender, RoutedEventArgs e) in C:\HPT\Measurements\HPT.Product.Measurement.UC\MeasurementReportUC.xaml.cs:line 219

 

System.IO.IOException: An attempt was made to move the file pointer before the beginning of the file.
 
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.SeekCore(Int64 offset, SeekOrigin origin)
   at System.IO.FileStream.Seek(Int64 offset, SeekOrigin origin)
   at Telerik.Windows.Zip.ZipArchive.ReadEndOfCentralDirectory()

 

Thanks in advance for your help,

Joel


Viewing all articles
Browse latest Browse all 78072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>