JavaScript operations Excel generate reports full Raiders _javascript tips

Source: Internet
Author: User
Tags set background
A recent project, using JavaScript to manipulate Excel to generate reports, below is an example of a detailed annotation
Copy Code code as follows:

<script language= "javascript" type= "Text/javascript" >

</script><script language= "javascript" type= "Text/javascript" >
function Makeexcel () {
var i,j;
try {
var xls = new ActiveXObject ("Excel.Application");
}
catch (e) {
Alert ("To print the table, you must have the Excel spreadsheet software installed, and the browser must use ActiveX controls, and your browser must allow the control to be executed.") Click "Help" to learn how to set up your browser! ");
Return "";
}
Xls.visible =true; Set Excel to Visible
var xlbook = xls. Workbooks.Add;
var xlsheet = xlbook.worksheets (1);
<!--combined-->
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (1,7)). Mergecells=true;
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (1,7)). value= "card issuing record";
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (1,6)). interior.colorindex=5;//set background color to blue
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (1,6)). font.colorindex=4;//Set Font Color
Xlsheet. Rows (1). Interior. ColorIndex = 5//Set background color to blue set back to Rows (1). Font.colorindex=4
<!--set row height-->
Xlsheet. Rows (1). RowHeight = 25;
<!--set the font ws. Range (ws. Cells (i0+1,j0), WS. Cells (I0+1,J1)). Font.Size =-->
Xlsheet. Rows (1). font.size=14;
<!--set Font xlsheet font settings for the selected area. Range (Xlsheet. Cells (i0,j0), WS. Cells (i0,j0)). Font.Name = "Blackbody"-->
Xlsheet. Rows (1). Font.name= "Blackbody";
<!--set column width xlsheet. Columns (2) =14;-->
Xlsheet. Columns ("A:d"). ColumnWidth = 18;
<!--set display characters instead of numbers-->
Xlsheet. Columns (2). Numberformatlocal= "@";
Xlsheet. Columns (7). Numberformatlocal= "@";

Sets the cell content wrap range. WrapText = true;
Sets the horizontal alignment range of the cell contents. HorizontalAlignment = excel.xlhalign.xlhaligncenter;//Set cell content vertical Stack method
Range. Verticalalignment=excel.xlvalign.xlvaligncenter
Range. WrapText = true; Xlsheet. Rows (3). Wraptext=true Automatic Line Wrapping
Set the title bar
Xlsheet. Cells (2,1). Value= "card number";
Xlsheet. Cells (2,2). value= "Password";
Xlsheet. Cells (2,3). Value= "Billing Method";
Xlsheet. Cells (2,4). value= "Effective Days";
Xlsheet. Cells (2,5). Value= "Amount";
Xlsheet. Cells (2,6). Value= "affiliated service project";
Xlsheet. Cells (2,7). Value= "card issuing time";
var otable=document.all[' Fors:data '];
var rownum=otable.rows.length;
for (i=2;i<=rownum;i++) {
for (j=1;j<=7;j++) {
HTML table class is written to Excel
Xlsheet. Cells (I+1,J). Value=otable.rows (i-1). Cells (j-1). InnerHTML;
}

}
<!--Xlsheet. Range (XLS). Cells (i+4,2), XLS. Cells (rownum,4)). Merge; -->
Xlsheet. Range (Xlsheet. Cells (I, 4), Xlsheet. Cells (i-1, 6)). Borderaround, 4
for (mn=1,mn<=6;mn++). Xlsheet. Range (Xlsheet. Cells (1, MN), Xlsheet. Cells (I1, J)). Columns.AutoFit;
Xlsheet. Columns.AutoFit;
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (rownum+1,7)). HorizontalAlignment =-4108;//Center
Xlsheet. Range (Xlsheet. Cells (1,1), Xlsheet. Cells (1,7)). VerticalAlignment =-4108;
Xlsheet. Range (Xlsheet. Cells (2,1), Xlsheet. Cells (rownum+1,7)). font.size=10;
Xlsheet. Range (Xlsheet. Cells (2,1), Xlsheet. Cells (rownum+1,7)). Borders (3). Weight = 2; Set left margin
Xlsheet. Range (Xlsheet. Cells (2,1), Xlsheet. Cells (rownum+1,7)). Borders (4). Weight = 2;//Set Right margin
Xlsheet. Range (Xlsheet. Cells (2,1), Xlsheet. Cells (rownum+1,7)). Borders (1). Weight = 2;//Set Top margin
Xlsheet. Range (Xlsheet. Cells (2,1), Xlsheet. Cells (rownum+1,7)). Borders (2). Weight = 2;//Set Bottom margin


Xls. UserControl = true; It's important, you can't omit it, or it's going to go wrong. Excel to User control
Xls=null;
Xlbook=null;
Xlsheet=null;
}


</script> <link href= "css/styles3.css" rel= "stylesheet" type= "Text/css"/>
<title>ziyuanweihu</title>
<body>
<form id= "fors" method= "post" action= "/webmodule/admins/card/showcard.faces" enctype= "application/" X-www-form-urlencoded ">


<table id= "fors:top" border= "0" cellpadding= "0" cellspacing= "0" width= "100%" >
<tbody>
<tr>
&LT;TD class= "left" ></td>
&LT;TD class= "Topmiddle" ></td>
&LT;TD class= "right" ></td>
</tr>
</tbody>
</table>


<table border= "0" cellpadding= "0" cellspacing= "0" width= "100%" >
<tbody>
<tr>
&LT;TD class= "Middleleft" ></td>
&LT;TD class= "Btstyle" ><table id= "Fors:sort" border= "0" cellpadding= "0" cellspacing= "0" style= "Valign:center" Width= "100%" >
<tbody>
<tr>
&LT;TD class= "Btstyle" ><input type= "button" Name= "Fors:_id7" value= "Generate Excel File" onclick= "Makeexcel ()"/>< Input type= "Submit" Name= "Fors:_id8" value= "return"/></td>
</tr>
</tbody>
</table>
<table id= "Fors:data" border= "1" cellpadding= "0" cellspacing= "1" width= "100%" >
<thead>
<tr>
<th scope= "col" ><span id= "FORS:DATA:HEADERTEXT1" > Card number </span></th>
<th scope= "col" ><span id= "fors:data:headerText2" > Password </span></th>
<th scope= "col" ><span id= "Fors:data:headerText3" > Billing method </span></th>
<th scope= "col" ><span id= "FORS:DATA:HEADERTEXT4" > Effective days </span></th>
<th scope= "col" > Amount </th>
<th scope= "col" ><span id= "FORS:DATA:HEADERTEXT6" > Affiliated Service Project </span></th>
<th scope= "col" ><span id= "FORS:DATA:HEADERTEXT7" > Card issuing Time </span></th>
</tr>
</thead>
<tbody>
<tr>
<td>h000010010</td>
<td>543860</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010011</td>
<td>683352</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010012</td>
<td>433215</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010013</td>
<td>393899</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010014</td>
<td>031736</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010015</td>
<td>188600</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010016</td>
<td>363407</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010017</td>
<td>175315</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010018</td>
<td>354437</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
<tr>
<td>h000010019</td>
<td>234750</td>
<td> Meter Point </td>
<td></td>
<td>2.0</td>
<td> Test Project </td>
<td>2006-06-23 10:14:40.843</td>
</tr>
</tbody>
</table>
</td>
&LT;TD class= "MiddleRight" ></td>
</tr>
</tbody>
</table>
<table id= "Fors:bottom" border= "0" cellpadding= "0" cellspacing= "0" width= "100%" >
<tbody>
<tr>
&LT;TD class= "Left" >

</td>
&LT;TD class= "Bottommiddle" > </td>
&LT;TD class= "Right" >

</td>
</tr>
</tbody>
</table>
<input type= "hidden" name= "fors" value= "Fors"/></form>
</body>

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.