2

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.

1
  • What XML file format do you want to save to? Commented Feb 4, 2010 at 12:58

2 Answers 2

3

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);   
Sign up to request clarification or add additional context in comments.

Comments

-1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.