简体   繁体   中英

Excel Conversion of SpreadsheetML to Open XML (XLSX)

Simple question. Does anyone know an easy way to convert SpreadsheetML (Excel 2003 XML) to the Open Document XML used for Excel 2007 (xlsx) files?

I've got a library that unfortunately doesn't read the XML format, so I need to try and find a way to read the data, that doesn't involve another library.

Any suggestions appreciated.

If you've got deep pockets Aspose.Cells can read/write both formats and should provide for really easy conversion without automation.

http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx

Aspose.Cells for .NET

Aspose.Cells for .NET is an award-winning Spreadsheet component that allows .NET developers to embed the ability to read, write and manipulate Excel spreadsheets into their own applications without needing to rely on Microsoft Excel.

Aspose.Cells for .NET is a mature, scalable and feature rich component that offers many functions that are way beyond the simple data exporting capabilities of other vendors. With Aspose.Cells for .NET developers can export data, format spreadsheets to the most granular level, import images, import charts, create charts, apply and calculate complex formulas, stream Excel data, save in various formats and much more - all this without the need to use Microsoft Excel or Microsoft Office Automation.

Pricing starts at $899 per developer for enterprise (internal) development and goes up from there very steeply.

An easy way would be to use Excel's COM Library (Excel 2007), but I think that's not the answer you are looking for.

What's your library capable of? You could use the Open XML SDK 2.0 to write the spreadsheet document based on the output of your library.

Best Regards

The file format has indeed changed significantly from SpreadsheetML to Office Open XML.

And, since now spreadsheet files are broken into multiple XML files (which are all then zipped), there's no real hope of an easy XLST solution.

The most straightforward course of action, unfortunately, is to automate Excel using a macro to open each SpreadsheetML files and do a "Save As" to the newer format. This can be done in Office 2003 with the Office 2007 file format plug-in. Perhaps this can be relegated to a batch process so the server is not directly involved?

If the data in the spreadsheets are trivial and follow a consistent format, you can write your own parser to import directly from the SpreadsheetML files.

Try using JODConverter . JODConverter allows conversion of SpreadsheetML using the OpenOffice.org or Libreoffice engine.

IIRC the Office 2003 format works like OpenDocument format: It's a ZIP file with XML files inside, so (if you have enough time/courage) you can open it, find the XML file that contains the data and finally deal with XML.

I know, this answer is for brave developers ;)

Regards.

check this code static void XlsToXlsx

static void XlsToXlsx (string sourceFile, string destinationFile)
{
    Type officeType = Type.GetTypeFromProgID("Excel.Application");

    Excel.Application app = new Excel.Application();
    app.DisplayAlerts = false;
    // Open Excel Workbook for conversion.
    Excel.Workbook excelWorkbook = app.Workbooks.Open(sourceFile);
    // Save file as CSV file.
    //excelWorkbook.SaveAs(destinationFile, Excel.XlFileFormat.xlCSV);
    excelWorkbook.SaveAs(destinationFile, Excel.XlFileFormat.xlOpenXMLWorkbook);
    // Close the Workbook.
    excelWorkbook.Close();
    // Quit Excel Application.
    app.Quit();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM