Free Support Forum - aspose.com

How can I read a Xml file with aspose and export data to excel (.xls) format

Hello All

I am a new comer to aspose cells for .Net. I have a Xml file and its Stylesheet (.xsl) file.
I wanted to ask how can I convert Xml file and XSL to Excel Sheet with Aspose cells. A small C# sample code will be really helpful. I have attached sample files with email. Thanks.


Hi,


Well, Aspose.Cells is ogriginally designed to work with or manipulate Excel spreadsheet file formats, so the General XML files cannot be read by the product. It does support all the MS Excel (97-2010) file formats, e.g XLS, XLSX, CSV, Tab Delimited, ODS, HTML, SpreadsheetML etc. If you could have your data in SpreadsheetML format which is a kind of XML file but MS Excel oriented, then you may use Aspose.Cells to read the file directly.

Now you have to use your own .NET APIs to read the xml file and save it to some container e.g DataSet/DataTable, now you may use Aspose.Cells APIs e.g Cells.ImportDataTable() to import the data to Excel sheet and then save the Excel file. See a demo code below:

Sample code:

DataSet ds = new DataSet();
FileStream fs = new FileStream(“e:\test2\myfile.xml”, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(fs);
ds.ReadXml(reader);
fs.Close();

Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Cells.ImportDataTable(ds.Tables[0], true, “A1”);
workbook.Save(“e:\test2\Excel_file.xls”);

Thank you.