[分享]客户端操作Excel文档

博客给出了浏览器表格导出到Excel和Word的代码示例。包含相关输入按钮代码,以及使用JavaScript实现表格数据导出到Excel的详细代码,如创建Excel应用对象、添加工作簿和工作表,将表格数据逐行逐列写入Excel等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码:

<input type="hidden" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<input type="hidden" name="out_excel" onclick="AutomateExcel();" value="导出到excel" class="notPrint">

<title>浏览器表格导出到Excel代码</title>
<input type="button" name="out_word" onclick="vbscript:buildDoc" value="导出到word" class="notPrint">
<input type="button" name="out_word1" onclick="javascript:AutomateExcel() " value="导出到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<hang;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>

转载于:https://www.cnblogs.com/goody9807/archive/2005/08/24/221679.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值