Hi,
I have 1000 xml files.
I want to convert them as excel files.
Thanks,
Darma
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhosh Kumar JayaramanPosted Dec 14, 2012, 12:35 AM
//Creating Excel book and sheet
object misValue = System.Reflection.Missing.Value;
Excel.Application myApp=new Excel.Application() ;
Excel.Workbook myWbk = myApp.Workbooks.Add(misValue);
Excel.Worksheet myWst = (Excel.Worksheet)myWbk.Worksheets.get_Item(1);
//reading xml and load into datasheet
DataSet ds = new DataSet();
XmlReader xmlFile ;
xmlFile = XmlReader.Create("C:\\Staff.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
//writing into excel
int i = 0;
int j = 0;
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
for (j = 0; j <= ds.Tables[0].Columns.Count - 1; j++)
{
myWst.Cells[i + 1, j + 1] = ds.Tables[0].Rows[i].ItemArray[j].ToString ();
}
}
//saving and closing excel
myWbk.SaveAs("C:\\Staffexcel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
myWbk.Close(true, misValue, misValue);
myApp.Quit();
source:http://csharp.net-informations.com/xml/excel-from-xml.htm
Lacy MichellePosted Dec 14, 2012, 12:39 AM
Convert Excel to XML and XML to Excel
Generate Excel from XML and Generate XML from Excel