JS exports the form to EXCEL

Source: Internet
Author: User

This is a good example. You can test it to understand it.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "description" content = ""/>
<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). Font. Bold = True
// OSheet. Cells (I + 1, j + 1). Font. Size = 50
// OSheet. Cells (I + 1, j + 1). Alignment = 2
OSheet. Cells (I + 1, j + 1). value = table. rows (I). cells (j). innerText;
}
}
OXL. Visible = true;
OXL. UserControl = true;
}
// -->
</SCRIPT>
</Head>
 
 
<Body>
<Table border = "1" width = "100%" id = "data">
<Tr>
<Td> & nbsp; name </td>
<Td colspan = "2"> age </td>
<Td> Date of Birth </td>
</Tr>
<Tr>
<Td> 6 </td>
<Td> 25 </td>
<Td colspan = "2"> 8 </td>
</Tr>
<Tr>
<Td height = "22"> 1 </td>
<Td height = "22"> 2 </td>
<Td colspan = "2" height = "22"> 4 </td>
</Tr>
</Table>
<Input type = "button" name = "out_excel" onclick = "AutomateExcel ();" value = "export to excel" class = "notPrint">
</Body>
</Html>
 
This article is from "Qiao Lei's blog learning and progress"

Related Article

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.