A cópia do código é a seguinte:
<html>
<head>
<Script Language = "JavaScript" type = "text/javascript">
função makexcel () {
var i, j;
tentar {
var xls = new ActiveXObject ("Excel.Application");
}
Catch (e) {
alerta ("Para imprimir esta tabela, você deve instalar o software do Excel Spreadsheet e o navegador deve usar" Controles do ActiveX "e seu navegador deve permitir a execução de controles. Clique em [Ajuda] para entender como definir o navegador!");
retornar "";
}
xls.visible = true; // Defina o Excel como visível
var xlBook = xls.workbooks.add;
var xlSheet = xlbook.worksheets (1);
<!-Merge->
xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,7)). Mergecells = true;
xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,7)). value = "registro de emissão de cartões";
// xlsheet.range (xlsheet.cells (1,1), xlsheet.cells (1,6)). interior.colorindex = 5; // Defina a cor de fundo como azul
// xlsheet.range (xlsheet.cells (1,1), xlsheet.cells (1,6)). font.colorindex = 4; // Defina a cor da fonte
// xlsheet.rows (1). Interior .ColorIndex = 5; // Defina a cor de fundo como azul. Defina as linhas de cores de fundo (1) .Font.ColorIndex = 4
<!-Defina a altura da linha->
xlSheet.Rows (1) .RowHeight = 25;
<!-Definir Fonte
xlSheet.Rows (1) .Font.Size = 14;
<!-Set Font Definir as fontes da área selecionada xlsheet.Range (xlsheet.cells (i0, j0), ws.cells (i0, j0)). Font.name = "Bold"->
xlsheet.rows (1) .font.name = "Boldbody";
<!-Defina a largura da coluna xlsheet.columns (2) = 14;->
xlsheet.Columns ("A: D"). ColumnWidth = 18;
<!-Defina os caracteres de exibição em vez de números->
xlsheet.columns (2) .NumberFormatlocal = "@";
xlsheet.columns (7) .NumberFormatlocal = "@";
// Defina o conteúdo da célula para envolver automaticamente o intervalo de linha.wrapText = true;
// Defina o alinhamento horizontal da faixa de conteúdo de células.horizontalalignment = Excel.xlhalig.xlhaligCenter; // Defina o método de empilhamento vertical do conteúdo de células
//range.verticalignment=excel.xlvalign.xlValigninter
//Range.WrapText = true; xlsheet.Rows (3) .WrapText = True Automatic Wapping
// Defina a barra de título
xlsheet.Cells (2,1) .Value = "Número do cartão";
xlsheet.Cells (2,2) .Value = "Senha";
xlsheet.Cells (2,3) .Value = "Método de cobrança";
xlsheet.Cells (2,4) .Value = "Número do valor de dias válidos";
xlsheet.Cells (2,5) .Value = "valor";
xlsheet.cells (2,6) .Value = "Item de serviço";
xlsheet.Cells (2,7) .Value = "Time de emissão";
var otable = document.all ['fors: dados'];
var rownum = Otable.Rows.Length;
for (i = 2; i <= robownum; i ++) {
for (j = 1; j <= 7; j ++) {
// O conteúdo da classe de tabela html é escrito para 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)). mescle; ->
// xlsheet.range (xlsheet.cells (i, 4), xlsheet.cells (i-1, 6)).
// for (mn = 1, mn <= 6; mn ++). xlsheet.Range (xlsheet.cells (1, mn), xlsheet.cells (i1, j)). colums.autofit;
xlsheet.columns.autofit;
xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (rownum+1,7))
xlsheet.Range (xlsheet.cells (1,1), xlsheet.cells (1,7)). VerticalAnigment = -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)). Fronteiras (3) .Weight = 2; // defina a margem esquerda
xlsheet.Range (xlsheet.cells (2,1), xlsheet.cells (rownum+1,7)). Borders (4) .weight = 2; // Defina a margem direita
xlsheet.Range (xlsheet.cells (2,1), xlsheet.cells (rownum+1,7)). Borders (1) .weight = 2; // Defina a margem superior
xlsheet.Range (xlsheet.cells (2,1), xlsheet.cells (rownum+1,7)). Borders (2) .weight = 2; // Defina a margem inferior
xls.userControl = true; // É muito importante e não pode ser omitido, caso contrário, haverá problemas. Isso significa que o Excel é deixado para o usuário controlar
xls = nulo;
xlbook = nulo;
xlSheet = null;
}
</script> <link href = "css/styles3.css" rel = "stylesheet" type = "text/css"/>
<title> ziyuanweihu </title>
</head>
<Body>
<form id = "fors" method = "post" action = "/webmodule/Admins/card/showcard.faces" Enctype = "Application/x-www-form-urlencoded">
<tabela id = "Fors: top" CellPadding = "0" CellPacing = "0">
<Tbody>
<tr>
<td> <img src = "Images/jiao1.gif"/> </td>
<Td> </td>
<Td> <img src = "Images/jiao2.gif"/> </td>
</tr>
</tbody>
</tabela>
<tabela CellPadding = "0" CellPacing = "0">
<Tbody>
<tr>
<Td> </td>
<td> <tabela id = "fors: classy" CellPadding = "0" CellPacing = "0" style = "Valign: Center">
<Tbody>
<tr>
<td> <input type = "button" name = "fors: _id7" value = "gere o arquivo excel" onclick = "makexcel ()" /> <input type = "submit" name = "fors: _id8" value = "return" /> < /td>
</tr>
</tbody>
</tabela>
<tabela id = "Fors: Data" CellPadding = "0" CellPacing = "1">
<head>
<tr>
<th scope = "col"> <span id = "fors: dados: headerText1"> número do cartão </span> </th>
<th scope = "col"> <span id = "fors: dados: headerText2"> senha </span> </th>
<th scope = "col"> <span id = "fors: dados: headerText3"> método de cobrança </span> </th>
<th scope = "col"> <span id = "fors: dados: headertext4"> dias válidos </span> </th>
<th scope = "col"> quantidade </th>
<th scope = "col"> <span id = "fors: dados: headerText6"> serviços </span> </th>
<th scope = "col"> <span id = "fors: dados: headertext7"> horário de emissão </span> </th>
</tr>
</head>
<Tbody>
<tr>
<TD> H000010010 </td>
<Td> 543860 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<td> h000010011 </td>
<Td> 683352 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<TD> H000010012 </td>
<Td> 433215 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<td> h000010013 </td>
<Td> 393899 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010014 </td>
<Td> 031736 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010015 </td>
<Td> 188600 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<Td> H000010016 </td>
<Td> 363407 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<TD> H000010017 </td>
<Td> 175315 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<TD> H000010018 </td>
<Td> 354437 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
<tr>
<TD> H000010019 </td>
<Td> 234750 </td>
<Td> Counting Points </td>
<Td> </td>
<Td> 2.0 </td>
<td> Projeto de teste </td>
<Td> 2006-06-23 10: 14: 40.843 </td>
</tr>
</tbody>
</tabela>
</td>
<Td> </td>
</tr>
</tbody>
</tabela>
<tabela id = "Fors: Bottom" CellPadding = "0" CellPacing = "0">
<Tbody>
<tr>
<Td>
<img src = "Images/jiao3.gif"/>
</td>
<Td> </td>
<Td>
<img src = "Images/jiao4.gif"/>
</td>
</tr>
</tbody>
</tabela>
<input type = "hidden" name = "fors" value = "fors" /> </morm>
</body>
</html>