在 http://blog.csdn.net/juwuyi/archive/2004/10/18/141255.aspx[url=http://www.51js.com/viewthread.php?fpage=2&tid=28197][/url]
提供的TDC的例子中增加下面这个函数可以将数据保存到Excel里。
<script language="JavaScript">
function SavetoExcel(){
var rst=tdcComposers.recordset;
var xlApp= new ActiveXObject("Excel.Application");
var xlWb = xlApp.Workbooks.Add();
var xlWs = xlWb.Worksheets("Sheet1");
//显示Excel
xlApp.Visible ="1";
xlApp.UserControl="1";
//给Excel添加列
var fldCount = rst.Fields.Count;
for (var iCol=1;iCol<=fldCount;iCol++){
xlWs.Cells(1, iCol).Value = rst.Fields(iCol - 1).Name;
}
//EXCEL 2000 or 2002: Use CopyFromRecordset
xlWs.Cells(2, 1).CopyFromRecordset(rst);
xlApp.Selection.CurrentRegion.Columns.AutoFit();
xlApp.Selection.CurrentRegion.Rows.AutoFit();
xlWs = null;
xlWb = null;
xlApp = null;
}
</script>