Print series-export a web page to an Excel document

Source: Internet
Author: User


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.

  1. <Title> export a browser table to excel </title>
  2. <Input type = "button" name = "out_word1" onclick = "automateexcel ()"
  3. Value = "export to excel" class = "notprint">
  4. <Table id = "data" width = "200" border = "1">
  5. <Tr>
  6. <TD> 11 </TD>
  7. <TD> 11 </TD>
  8. </Tr>
  9. <Tr>
  10. <TD> 22 </TD>
  11. <TD> 22 </TD>
  12. </Tr>
  13. <Tr>
  14. <TD> 33 </TD>
  15. <TD> 33 </TD>
  16. </Tr>
  17. <Tr>
  18. <TD> 44 </TD>
  19. <TD> 44 </TD>
  20. </Tr>
  21. </Table>
  22. <Script language = "JavaScript">
  23. Function automateexcel ()
  24. {
  25. // Start Excel and get application object.
  26. VaR oxl = new activexobject ("Excel. application ");
  27. // Get a new workbook.
  28. VaR owb = oxl. workbooks. Add ();
  29. VaR osheet = owb. activesheet;
  30. VaR table = Document. All. Data;
  31. VaR hang = table. Rows. length;
  32. VaR lie = table. Rows (0). cells. length;
  33. // Add Table headers going cell by cell.
  34. For (I = 0; I
  35. {
  36. For (j = 0; j <lie; j ++)
  37. {
  38. Osheet. cells (I + 1, J + 1). value = table. Rows (I). cells (j). innertext;
  39. }
  40. }
  41. Oxl. Visible = true;
  42. Oxl. usercontrol = true;
  43. }
  44. </SCRIPT>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.