日期:2014-05-17  浏览次数:20975 次

新手请教将查询到的数据生成EXCL文件
我已经做好了报表,但是现在想把报表生成EXCL文件,在网上搜索到的文章都是一个内容,按照上面试验了,没成功!特在此请教各位达人!

------解决方案--------------------
一般的做法: Response.ContentType = "application/ms-excel " Response.AddHeader( "content-disposition ", "attachment;filename=aa.xls "))
------解决方案--------------------
用Excel的Application组件在客户端导出到Excel或Word
  
注意:
1.函数中的“data“是网页中要导出的table的 id
2.客户电脑上必须装有ms excel
3.必须打开ie里面的active x安全设置


<input type= "button " name= "out_excel " onclick= "AutomateExcel(); " value= "导出到excel " class= "notPrint ">


导出到Excel代码
<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>