I'm trying to open a "xls" file in c# and save as an xml,like if i did from excel. I don't need to read the file,just to convert in xml with the same format if i did it with Microsoft Excel. If anyone have any leads,thanks.
2 Answers
This is how i did it,if it interest anyone.
Microsoft.Office.Interop.Excel.Application _excelApp = new Microsoft.Office.Interop.Excel.Application();
Workbook workBook = _excelApp.Workbooks.Open(@"d:\test.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
workBook.SaveAs(@"d:\test.xml",
Microsoft.Office.Interop.Excel.XlFileFormat.xlXMLSpreadsheet,
null,
null,
true,
true,
XlSaveAsAccessMode.xlNoChange,
Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges,
true,
null,
null,
false);
workBook.Close(null,null,null);
Comments
Easy way:
- Start recording an Excel macro
- Grab it's VBA source; now you know to do
- Translate that to C#
- Use Excel Interop to interact with your workbook