0

I want to export an HTML table to excel sheet.
I would have done this with CVS format if I didn't have to keep some formatting and add pictures.

I have tries using the Office 2003 XML format for that, i.e.

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
          xmlns:o="urn:schemas-microsoft-com:office:office"
          xmlns:x="urn:schemas-microsoft-com:office:excel"
          xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
          xmlns:html="http://www.w3.org/TR/REC-html40">
    <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
    ...
    </DocumentProperties>
    <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
    ...
    </OfficeDocumentSettings>
    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
    ...
    </ExcelWorkbook>
    <Styles>...</Styles>
    <Worksheet ss:Name="Sheet1">...</Worksheet>
</Workbook>

And then some JavaScript code to "download" it using data URI and

'data:application/vnd.ms-excel;charset=utf-8, '+
 encodeURIComponent(STRING_XML_REPRESENTATION));

I have 2 problems:

  1. The document saved as xls (or xlsx) opens fine on OpeOffice \ LibreOffice but throws an error on Excel, and
  2. I do not seem to find a way to add images to the file.

I do not want to save it as an xml file since opening it defaults to a web browser in most cases.

1 Answer 1

1

Review ECMA-376. Excel expects all of the files to be included in a zip container (and you must have a few additional files, including [Content_Types].xml)

Images must be added to the zip container and referenced (review the spec).

Sign up to request clarification or add additional context in comments.

1 Comment

How can I do this programatically?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.