[原创]将TDC进行到底:将数据保存到Excel里

类别:网站制作 点击:0 评论:0 推荐:


在 http://blog.csdn.net/juwuyi/archive/2004/10/18/141255.aspx

提供的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>

本文地址:http://com.8s8s.com/it/it31285.htm