Convert a xml to xlsx in C# - c#

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)

Related

How to generate a complex json file from excel worksheet

I have an excel file with few columns. I want to write a react
application that will upload/open the excel file, retrieve the data
row by row and generate a complex json file and store it on a server.
I have the schema of what the json file will look like.
How do I start the generation of this json file? Is it also better to
do this on the client side or server side? I am using json.net and new to this.
I recommend you look into using the EPPlus library with the Newtonsoft Json.NET library.
You can read a file upload directly into an Excel package without saving anything to disk, extract the data you need by reading the Excel Worksheet and then create a generic List of a custom class that represents the data you want to serialize, then serialize that list into JSON using JsonConvert.SerializeObject.

Importing data into Excel using XML and Excel Templates

I am generating CSV data from a C# application. This can be imported into Excel easily but I need formatting applied to the file.
One option is interop but the machine running this application will not have Office products installed so that is out.
I've been told that XML can work with Excel templates and am looking for a starter example on how to achieve this.
I have generated excel spread sheets using the excel 2003 xml format several times but you will have to consider the following features that cannot be supported using this format:
This XML Spreadsheet 2003 file format (.xml) does not retain the following features:
Auditing tracer arrows
Chart and other graphic objects
Chart sheets, macro sheets, dialog sheets
Custom views
Data consolidation references
Drawing object layers
Outlining and grouping features
Password-protected worksheet data
Scenarios
User-defined function categories
VBA projects
If that is acceptable you can use as someone suggest an open source library that allows you to generate the spreadsheet in code or as I have done you can generate the xml using either an xml transform or a using the spark template engine. Both have worked for me in the past but using the spark view engine was probably the nicest.
The best way to achieve either of these is to create a template the way you want it to look and save it as a Excel 2003 Xml format and look at the raw xml. This should make it easy for you to generate your output. You can also download the xml definition for reference.
You can use excellent OpenXML wrapper ClosedXML to generate xlsx files with formatting. Or if you want, you can use pure OpenXML. OpenXML installation is required for ClosedXML to work.

Need to stream Excel file to web clients

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

Export to XML then to Excel (to make the export faster)

hi i want to export an entity framework query to excel if i use Microsoft.Office.Interop.Excel , it takes about 3 minutes . is there any other method to export the query to excel faster?
by the way i have to manipulate query info in loop while creating excel worksheet.
thank you.
you need to find where the "slowness" come in.
have you try changed the program to output to simple text file? is it as slow as export to Excel?

open xml to query excel cells

In the past, I have created a component to pass and retrieve values to/from excel using the excel libraries. The good thing is that once you have your workbook in memory and modify a cell (let's call it the origin cell) all the other cells with formulas that take this origin cell value are automatically refreshed.
Is this possible in OpenXml?
As far as I see, apparently this doesn't happen in OpenXml because the excel engine is not really executed in the background, OpenXml is just a group of classes to serialize, deserialize, read etc xml files right?
That's correct, Office Open XML SDK is just a set of libraries to read/write XML files. It does not have any functionality for performing calculations.
You can specify that Excel should recalculate everything upon load by setting the following attribute, but if you need to read the new values in code (prior to re-opening in Excel) this won't help.
<workbook>
<calcPr fullCalcOnLoad="1"/>
</workbook>
Or in code with the Office Open XML SDK..
using (var doc = SpreadsheetDocument.Open(path, false))
{
doc.WorkbookPart.Workbook.CalculationProperties.FullCalculationOnLoad = true;
.
.
.
}

Categories