不为失败找借口,只为成功找方法!
分类: Java
2015-07-05 15:05:04
用JavaScript脚本生成XLS文件
functionCreateXLS(){
if ( dssub1.RecordCount==0 ){
alert("导出单据列表为空! ");
return;
}
ShowWait("正在导出数据至Excel,,请稍候...");
//vardwname = Trim(DsMain.Field('dwmch').Value);
// 加载ActiveX控件,获取Excel句柄
var oXL = null;
try {
oXL= new ActiveXObject("Excel.Application");
}
catch(e)
{
alert("创建Excel失败!");
return;
}
//alert("正在导出数据至Excel,,请稍候...");
// 创建一个Excel文件
var oWB = oXL.Workbooks.Add();
// 创建一个Excel文件
var oSheet = oWB.ActiveSheet;
var table = document.all.Report;
var hang = dssub1.RecordCount;
var lie = dssub1.FieldCount;
for (i=0;i <hang;i++)
{
for (j=0;j <lie;j++)
{
oSheet.Cells(i+1,j+1).value = dssub1.GetValueAt(i,j);
}
}
//oXL.Visible = true;
//oXL.UserControl = true;
varflname = "\\发票_" + SKDBedit1.value +'至'+ SKDBedit2.value ;
oWB.SaveAs (flname);
alert("导出成功");
oXL.Quit();
oXL = null;
// HideWait();
// CloseBill();
// 调用Cleanup()进行垃圾回收
idTmr = window.setInterval("Cleanup();",10);
st = null;
varsql = "";
for (var n = 0; n < dssub1.RecordCount; n++) {
sql += " update cwk set is_dc='是' where djbh='" + dssub1.GetValueAt(n, 'djbh') + "' ";
}
try {
InsertSql(sql);
} catch(e) {
alert(e.message);
}
uf_Onload();
dssub1.OpenEmpty();
}
function createXML(){
//xml文件名 } |