Hi,
Actually I use the UltraWebGridExcelExporter (10.3 on ASP.NET 2.0) to export a grid to .xls using the following code:
this.xlsExport.DownloadName = "result.xls"; Infragistics.WebUI.UltraWebGrid.UltraWebGrid resultGrid = this.resGrid.GetGrid(); this.xlsExport.Export(resultGrid);
This works fine, but now I want to allow exporting to Office 2007+ file format .xlsx. If I just pass a DownloadName "result.xlsx", I will get a file "result.xlsx.XLS". :(I've also tried to do the following:
this.xlsExport.DownloadName = "result.xlsx"; Infragistics.WebUI.UltraWebGrid.UltraWebGrid resultGrid = this.resGrid.GetGrid(); Infragistics.Excel.Workbook wb = new Infragistics.Excel.Workbook(); wb.SetCurrentFormat(Infragistics.Excel.WorkbookFormat.Excel2007); this.xlsExport.Export(resultGrid, wb);
But then I get the following error:
Exception of type 'System.Web.HttpUnhandledException' was thrown.Stack Trace:System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NotSupportedException: packageFactory cannot be null. When saving to Excel2007 workbook format and using the Infragistics2.Excel assembly, you must provide an IPackageFactory to handle the packaging of data. If you are using the DotNet Framework 3.0 or higher, use the Infragistics3.Excel assembly instead, and the packaging will be handled by the WindowsBase class
How to get that working?
Best Regards
It sounds like you are using the CLR 2 versions of the assemblies. CLR 2 did not have support for putting files into zip packages, which is required for writing out .xlsx files. That is why it is asking you to supply an IPackageFactory, because the burden of zipping is on the developer with the CLR 2 versions. But if you use the CLR 3 assemblies or later, zipping is done automatically. So if you are using the ASP.NET assemblies, make sure to use those prefaced with "Infragistics35." or "Infragistics4."
This is still a problem in 2011.1, The CLR 3 version creates the format well enough but when you go to export it, it always tags .XLS onto the filename reguardless of the workbook format.
Workbook wkbk = new Workbook(WorkbookFormat.Excel2007);
Worksheet sheet = wkbk.worksheets.Add(sheetname + page);
UltraWebGridExcelExporter exporter = new UltraWebGridExcelExporter();exporter.DownlaodName = "mydoc.xlsx";
exporter.Export(grid, sheet, 0, 0);
this will kick a document to the browser that is named "mydoc.xlsx.XLS" when I save it and open it, excel will complain that the doc format is not the same as the extension. If I rename the file and strip the .XLS off it opens as an xslx just fine.
So the UltraWebGridExcelExporter either needs to get smarter by looking at the format that is set in the workbook or get dumber and let us set the extension.
Hi Mike,
thanks for your reply!
Yes, thats right, as I mentioned, the application is running on ASP.NET 2.0, and CLR 2 assemblies are used. Migrating the application to 3.5/4.0 is not possible in my case. If I would provide a IPackageFactory implementation, how to set it to the WorkBook when using the UltraWebGridExcelExporter.Export(grid, workbook) method for the export and not the WorkBook.Save(file, packageFactory) method?
Andreas