I have a method that converts a SQL query into a DataView and now I'm trying to convert a DataView to an Excel document that can be streamed from an asp.net site.
I've tried generating a .csv file but Excel would mess up the format.
Then tried OpenXML it appears super slow.
I just need to write out some basic table data so it can be modified in Excel and re-imported.
For creating an excel file you could use the Infragistics Excel engine. There is an example of how to create an excel file from a DataTable here: http://help.infragistics.com/NetAdvantage/ASPNET/Current/CLR3.5/?page=ExcelEngine_Populating_a_Worksheet_from_a_DataSet.html
You could then load the data again from the excel file format as well. If you want to test this you could do so with a trial of NetAdvantage for ASP.NET if you don't already have this:
http://www.infragistics.com/dotnet/netadvantage/aspnetdownloads.aspx
Related
I'm trying to filter an excel file and save the filtered data (as data objects) to a MySQL database. I tried to filter the excel file with the Spire XLS package which worked well. The only problem is that when I use an excel file with 30.000 lines it takes about 15 minutes to filter the file.
I am trying to look for a solution that filters this excel file in seconds. I was thinking of using a dataframe for this but then I still need to convert the excel file to the dataframe. I am unsure how long this convertion process will take. Any suggestions for this problem are much appreciated.
I was developing an application which read data from an excel file, but when I try to open it, an exception was thrown if the source file is saved with the xls format (File contains corrupted data error when opening Excel sheet with OpenXML). indeed when I save this file with the xlsx format it works fine. please help me to solve this problem.
Use Free Spire.XLS dll available via NuGet.
Sample:
Workbook workbook = new Workbook();
workbook.LoadFromFile("Input.xls");
workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);
For reliably reading XLS files you could use ExcelDataReader which is a lightweight and fast library written in C# for reading Microsoft Excel files. It supports the import of Excel files all the way back to version 2.0 of Excel (released in 1987!)
Alternatively you could use a file conversion API like Zamzar. This service has been around for 10+ years, and provides a simple REST API for file conversion - it supports XLS to XLSX conversion. You can use it in C# and it has extra features like allowing you to import and export files to and from Amazon S3, FTP servers etc.
Full disclosure: I'm the lead developer for the Zamzar API.
You cannot read xls files with OpenXML.
The solution from Microsoft is to read the xls file with Office Interop (but Interop is not recommended to be used on the server), transfer data from Interop step by step to OpenXML.
Another solution is to use an Excel library like EasyXLS and convert between these two Excel file formats:
ExcelDocument workbook = new ExcelDocument();
workbook.easy_LoadXLSFile("Excel.xls");
workbook.easy_WriteXLSXFile("Excel.xlsx");
Find more information about converting xls to xlsx.
I am not quite sure why you need to convert the file and why you don't just read the xls file, using a different technology then OpenXML, for sure.
XLS is the older Excel file format. XSLX is the newer format stored as OpenXML. XSLX is actually a zip file with the various components stored as files within it. You cannot simply rename the file to get it into the new format. To save the file in XSLX you'll have to save the file into the Excel 2010+ format.
If you're using Excel interop then it is an option on the SaveAs method.
for more info check the function: _Workbook.SaveAs Method
and the property: FileFormat:
Optional Object.
The file format to use when you save the file. For a list of valid choices,
see the FileFormat property. For an existing file, the default format is the
last file format specified; for a new file, the default is the format of the
version of Excel being used.
msdn info here:
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel._workbook.saveas(v=office.11).aspx
I have a large grid and i need those data exported to excel.i implemented my solution using openxml, however having nested loops fill each row's columns to set cell values is time consuming.
I'm now trying to export it to xml and then export to xlsx to improve performance.i converted the dataset to xml, now i'm stuck with converting to xlsx. is there a way to convert to xlsx without having nested loops to fill each cell value ?
UPDATE : I was able to do it using following library -
Open XML Format SDK 2.0 Sample - Convert XML to Excel File
There is no direct conversion, but your best bet if you have the XML is to deserialise this so you have access to the data via code, then build an Excel document using an Excel Library (e.g.: http://epplus.codeplex.com)
What is the fastest way of reading all data rows from a specific Excel Workbook Sheet into an ADO.NET DataTable using C#. The Excel Workbook will be approximately 30MB.
I do not want to use ODBC as i will have issues with getting it installed on the server machine.
My preference is a solution that uses the StreamReader Class, but any solution that doesn't use StreamReader is welcome except one that uses ODBC.
in case ms office is installed on the server, the fastest way would be to export the excel sheet into a CSV file and then using file IO to import it into your database.
you could open excel via COM Interop and export the workbook to CSV. others here on stackoverflow discussed this proceeding: Save an excel file to a csv file in C# code
i've got the experience that getting data out of excel directly via com interop is very slow. excel exports csv really fast instead.
[edit]
a very good office wrapper is NetOffice. It works similar like the COM Interop interface but with more speed and more function: http://netoffice.codeplex.com/
as you prefer stream reader, there's an excel binary reader on codeplex too: http://exceldatareader.codeplex.com/
[/edit]
I have html table in Microsoft.Office.Interop.Outlook.MailItem body and I just need to fill excel sheet with this table using C# for desktop application. Could any one help me in this regard. Thanks
A quick and dirty way:
File.WriteAllText(#"C:\Temp\Table.xls", mailItem.Body);
Excel will open it even though the file does not contain a valid xls document
You can also use HtmlAgilityPack to parse the e-mail and EPPlus to write to Excel (only 2007/2010 xlsx version).