前端

img juwuyi

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

发表于2004/10/27 14:10:00  1176人阅读



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>
阅读全文
0 0

相关文章推荐

img
取 消
img