c# store data in Excel file
I am obtaining data from a database that is returned in an XML string. What is the best way to then sto开发者_运维百科re 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 .
精彩评论