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
Related
In my application I already have functionality to export into 2003 format. Where I am constructing a string out of the template and write using System.IO.File.WriteAllText.
But it does not work with excel 2007/2010, that's why I wanted to convert it to Openxml in order to support 2007 and 2010.
I have string ready with creation of cells and rows from template.
I want advice on how to achieve or any body has reference link.
Please let me know.
Regards
WriteAllText class will save you a text file. You are saving an html(text) based file with xls extension. This is not a real xls file (that is actually a binary file), but MS Excel recognize and interpret the html format.
An xlsx file is a binary file. You can use OpenXML Office library ( Excel.XlFileFormat.xlOpenXMLWorkbook ) or another .NET Excel library like EasyXLS. Check this sample of code for more details.
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
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
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 .
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.