This method can only export the page tables of general rules. It is not applicable to complicated formats such as merging cells. You must consider using other components.
- <Title> export a browser table to excel </title>
- <Input type = "button" name = "out_word1" onclick = "automateexcel ()"
- Value = "export to excel" class = "notprint">
- <Table id = "data" width = "200" border = "1">
- <Tr>
- <TD> 11 </TD>
- <TD> 11 </TD>
- </Tr>
- <Tr>
- <TD> 22 </TD>
- <TD> 22 </TD>
- </Tr>
- <Tr>
- <TD> 33 </TD>
- <TD> 33 </TD>
- </Tr>
- <Tr>
- <TD> 44 </TD>
- <TD> 44 </TD>
- </Tr>
- </Table>
- <Script language = "JavaScript">
- Function automateexcel ()
- {
- // Start Excel and get application object.
- VaR oxl = new activexobject ("Excel. application ");
- // Get a new workbook.
- VaR owb = oxl. workbooks. Add ();
- VaR osheet = owb. activesheet;
- VaR table = Document. All. Data;
- VaR hang = table. Rows. length;
- VaR lie = table. Rows (0). cells. length;
- // Add Table headers going cell by cell.
- For (I = 0; I
- {
- For (j = 0; j <lie; j ++)
- {
- Osheet. cells (I + 1, J + 1). value = table. Rows (I). cells (j). innertext;
- }
- }
- Oxl. Visible = true;
- Oxl. usercontrol = true;
- }
- </SCRIPT>