I am obtaining data from a database that is returned in an XML string. What is the best way to then store this in an Excel file? Is there an XML - Excel tool, or is there an interim step?
Thanks.
The easiest way is probably just to loop through the XML-data either with XMLDocument or XDocument (linq) and write to a csv-file. The advantage with at csv file is that its readable with any text editor or other spreadsheet software.
You can read the data using the XMLDocument and then insert the data in the excel using Microsoft.Excel namespace.
Providing you're talking about Excel 2007 or newer, the format is XML-based. Check out any resources on OpenXML such as http://openxmldeveloper.org/ for details, or there's a video tutorial here that shows it http://www.asp.net/linq/videos/how-do-i-create-excel-spreadsheets-using-linq-to-xml . There's even things like http://code.google.com/p/linqtoexcel/ and an SDK here http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en .
Related
I'd like to transform my XMLDocument containing what you'd call simple xml content into an xls file, possibly using XSLT (judging from what I've found so far) to transform the data, and I'd like the save the created file as an xls file to be opened with Excel whilst not being able to use Excel in the process of creating this file (thus being unable to use MS.Office.Interop.Excel from what I've heard). How exactly would I do this and which classes would I utilize to create this document?
Any help on this one would be greatly appreciated!
Thanks,
Dennis
Probably your best bet is NPOI, a .NET port of the Apache POI library.
You can't use XSLT to create a XLS file, because XLS is a binary format.
If you are talking about ExcelML, this can be done. If you want to do it by hand, I think the best way to start is the following:
Create an ExcelML file using Excel that looks like what you need. Open this file in a text editor and analyse it. Additionally, you should download the reference of the format (Open Help -> OfficeXMLSDK.chm).
There are 3 wasy to convert XML to Excel XLS.
- If the XLS file layout is simple, just transform your XML to an HTML table, and load in Excel (either from a disk file, or HTTP response). This works for many cases, however beware that column / row spanning really confuses Excel.
- If you have a complex layout, with lots of formatting / worksheets, jump into the OfficeXMLSDK, it's pretty hairy with tons of namespaces
- If you have Excel on the server, create a template document in Excel, and use the Excel.Interop
I need to read an Excel work book with 2 sheet which have more than 60,000 records. The application is an ASP.Net application so the performance matters.
Which approach should I take? Should I do it using Microsoft.Office.Interop.Excel or should I do it using OLEDB in ADO.Net?
What is the best approach?
Split the book into two worksheet files, convert them to CSV (comma-separated value) form, and process them as text.
I think that would be the best approach perfomance-wise, if you only need to read the data and do not care about formatting, merged cells, formulae etc.
I used always OLEDB in ADO.Net for it.
What the best aproach is, I don't know. But the easiest is like Kaerber says, to read it as 2 .csv files.
Then you can read it like you read a .txt file without 'fancy' libraries.
Use OLEDB for querying (reading) and Interop when modifying Excel.
You can consider using:
gemboxsoftware.com/spreadsheet
or the free alternative:
http://npoi.codeplex.com/
Hi can any one let me know the code to export the xml file to Excel file.
you can load your xml file to dataset first and then from dataset you can generate excel file. You should get plenty of examples by doing google search for 'xml to dataset in c#' and 'dataset to excel in c#'
You don't need .NET for that; Excel has can store spreadsheets as XML, so you need to convert your XML into a format that Excel understands.
Those conversions can be done very well using XSLT.
This article gives you a nice introduction on how to do that.
--jeroen
How to convert Excel file to xml file using .NET framework 3.5
Please tell the approaches
The format of excel sheet is xls and convert to standard xml format
SpreadsheetGear for .NET will let you open a workbook (xls or xlsx format), get the formatted text (such as $5.00) with the IRange.Text property or the unformatted raw value with the IRange.Value property. You can also modify values and recalculate if needed. You would need to use the .NET XML APIs to write out the formatted text or unformatted values to an XML file.
You can download a free trial here if you want to try it yourself.
Disclaimer: I own SpreadsheetGear LLC
You can do it in various ways based on your requirement
You can read it like a database using OleDbConnection object to connect to the file and read data
You can use System.IO.Packaging to read office 2007 (xlsx) files
You can also use Excel.Application object model to read information from Excel
It really depends on your requirement what method is effective for you.
I want to create XML file from my Excel file through .NET (c#). My data is in Excel and it will be added in XML file.
Thanks.
Manoj
There is good article in CodeProject about it. Generally the answer is, that Excel can be used as Data provider. Later, when you get data out, you can use XMLDom to generate XML file