Adding worksheet to the excel file using javascript

后端 未结 1 1557
情深已故
情深已故 2020-12-15 02:06

Just assume I have 3 tables. I want to insert tables in 3 work sheets (per page one table) into a single excel file (without need of ActiveXObject)

1条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 02:28

    The approach you have shown uses a mixture of Spreadsheet XML and HTML. With this mixture it is not possible to fill multiple worksheets. To do this we have to use only Spreadsheet XML consequently. This is because only XML can describe multiple worksheets. The HTML table data is not related to any worksheets except the active worksheet.

    To use only Spreadsheet XML is possible, but then we have to work carefully with data types. If Excel imports HTML, it tries to detect data types as if the user would enter the values into cells manually. With XML it does not so. It takes the given data types from the XML. If they do not fit, then it produces errors. So in my example, I use "data-" attríbutes to describe the data-type, data-style and data-value. So it is possible to have the data-value different from the data presentation within the HTML table cell (TD). Since HTML is a format for data presentation and not for data exchange, this is also good practice in my opinion.

    For Spreadsheet XML see: http://msdn.microsoft.com/en-us/library/aa140066.aspx

    The example uses data URI as download link, so it works only with browsers that support this. It will not work with Microsoft Internet Explorer.

    Example:

     
    
    
    Name Birthday Amount Rebate (10%)
    Smith Mar 23 1980 $ 1,234.56 $ 123.45
    Doe Nov 05 1978 $ 2,345.67 $ 234.56

    Product Price Available Count
    Bred $ 1.89 yes 123
    Butter $ .89 no 0

    Fiddle: http://jsfiddle.net/qxLn3h86/

    Greetings

    Axel

    0 讨论(0)
提交回复
热议问题