|
|
使用Jscript编写EXCEL导出,希望对各位有用! |
|
|
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
下面是一段关于采用JSCRIPT语言对EXCEL的导出,下面的程序是对导出的关键一段,读者可以自己参考EXCEL用户手册进行修改。
function exportexcel() { var iSubjectNum,iElementNum; var sText; var iX=1; var iY=2; var xlsub; // alert('export'); IniExcel(); xlApp.visible=false; if (fso.FileExists(sExcelPath)==true ) { xlsub=xlApp.Application.Workbooks.Open(sExcelPath); //alert(xlsub); //xlsub=xlApp.Application.Worksheets(ipage); } else{ xlApp.Workbooks.Add(); //xlsub=xlApp.Application.Worksheets(1); //ipage=1; } var sheetcount=xlApp.Application.Worksheets.Count; var addcount=ipage-sheetcount; if (addcount!=0){ for(var m=0;m<addcount;m++) xlApp.Application.Worksheets.Add(); } //ѰÕÒÊÇ·ñÓÐÏàͬµÄSHEET var bFlag=false; var isheetpos=-1; for (var n=1;n<=sheetcount;n++) { if (xlApp.Application.Worksheets(n).Name==("Sheet"+ipage.toString())) { bFlag=true; isheetpos=n; } } if (bFlag==false ) { xlApp.Application.Worksheets.Add(); ipage=1; } else { ipage=isheetpos; } xlsub=xlApp.Application.Worksheets(ipage); xlsub.Cells(1,1).Value =oHead.ReportName.toString(); sText=of_convert_char(1)+"1:"+of_convert_char(iColumnNum)+"1"; xlsub.Range(sText).Merge(true); xlsub.Range(sText).HorizontalAlignment=3; xlsub.Range(sText).Font.Size=20; xlsub.Range(sText).Font.Bold=true; iSubjectNum=oHead.oSubject.length; iY=iY+1; for(var i= 0; i<iSubjectNum;i++) { if (oHead.oSubject[i].oElement==null){ xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString(); var temp=iY+3; sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString(); xlsub.Range(sText).Merge(false); xlsub.Range(sText).HorizontalAlignment=3; xlsub.Range(sText).Borders.LineStyle=1; xlsub.Range(sText).Font.Size=10; continue; } else iElementNum= oHead.oSubject[i].oElement.length; xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString(); sText=of_convert_char(iX)+iY+":"+of_convert_char(iX+iElementNum-1)+iY; xlsub.Range(sText).Merge(true); xlsub.Range(sText).HorizontalAlignment=3; xlsub.Range(sText).Borders.LineStyle=1; xlsub.Range(sText).Font.Size=10; iY=iY+1; for(var j=0;j<iElementNum;j++){ xlsub.Cells(iY,iX).Value =oHead.oSubject[i].oElement[j].ElementName.toString(); var temp=iY+2; sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString(); xlsub.Range(sText).Merge(false); xlsub.Range(sText).HorizontalAlignment=3; xlsub.Range(sText).Borders.LineStyle=1; xlsub.Range(sText).Font.Size=10; iX=iX+1; } iY=iY-1; } iY=iY+3; for (var i=0;i<iRowNum;i++) { iY++; for (var j=0 ;j<iColumnNum;j++) { xlsub.Cells(iY,j+1).Value=oBody[i][j].toString(); xlsub.Cells(iY,j+1).Borders.LineStyle=1; xlsub.Cells(iY,j+1).Font.Size=10; } } if (fso.FileExists(sExcelPath)==true ) { var thiswork=xlApp.Application.ActiveWorkbook; thiswork.Saved=true; thiswork.Save(); thiswork.Close(true); } else xlsub.SaveAs(sExcelPath); window_onunload(); alert("Îļþ´æ·ÅÔÚ£º"+sExcelPath); }
|
|
相关文章:相关软件: |
|