office

位置:IT落伍者 >> office >> 浏览文章

如何实现将统计表格保存成excel文件


发布日期:2021年01月30日
 
如何实现将统计表格保存成excel文件

javajspjavascript中如何实现将统计表格保存成excel文件?

&lt SCRIPT LANGUAGE=JavaScript &gt

function AutomateExcel()

{

var ij;

// Start Excel and get Application object

var oXL = new ActiveXObject(ExcelApplication);

oXLVisible = true;

// Get a new workbook

var oWB = oXLWorkbooksAdd();

var oSheet = oWBActiveSheet;

// Add table headers going cell by cell

// tblout表的ID

for(i=;i&lt tbloutrowslength;i++)

for(j=;j&lt tbloutrows(i)cellslength;j++)

oSheetCells(i+ j+)Value = tbloutrows(i)cells(j)innerText

oXLVisible = true;

oXLUserControl = true;

}

&lt /SCRIPT &gt

//这个问题其实你搜一下就有了

首先你的页面上要有一个按钮save

这个按钮先做查询数据库然后action转到保存excell的页面即我给你的这些代码由于我的是用这个页面是隐藏的点击save时有跳出界面问你是打开还是保存xxxxxxxxxxxxxx是你调用数据库的记录

&lt %@ page contentType=text/html;charset=gb % &gt

&lt %@ page import=javalang*% &gt

&lt %

try{

responsesetContentType(Application/msexcel);

responsesetHeader(ContentDisposition attachment;filename=trainlistxls);

StringBuffer cont=new StringBuffer();

% &gt

&lt HTML &gt

&lt HEAD &gt

&lt META httpequiv=ContentStyleType content=text/css &gt

&lt /HEAD &gt

&lt BODY &gt

&lt br &gt&lt br &gt&lt br &gt

&lt %

int status = khViewBeangetStatus();

if (status == ){

int rscount = khViewBeangetRSCount();

% &gt

&lt %

contappend(&lt html &gt&lt head &gt&lt META content=′text/html; charset=gb′ httpequiv=ContentType &gt&lt /head &gt&lt body &gt );

contappend(&lt h &gt SOP??μμé?ˉ?á?&lt /h &gt);

contappend(&lt table width=′%′ border=′′ &gt );

contappend(&lt tr &gt );

contappend(&lt td height=′′ &gt???to? &lt /td &gt );

contappend(&lt td height=′′ &gt???t?? &lt /td &gt );

contappend(&lt td height=′′ &gt??? &lt /td &gt );

contappend(&lt td height=′′ &gtéúD§ê±?? &lt /td &gt );

contappend(&lt /tr &gt );

contappend(&lt tr &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt /tr &gt );

contappend(&lt tr &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );

}

contappend(&lt /table &gt );

contappend(&lt /body &gt&lt /html &gt );

responsegetWriter()println(conttoString());

responsegetWriter()close();

% &gt

&lt %

}

else if (status &gt ) {

% &gt

&lt hr color=#CC &gt

&lt span class=text &gt&lt font color=blue size= &gt&lt center &gt&lt P &gt?Têy?Y &lt /P &gt&lt /center &gt&lt /font &gt&lt /span &gt

&lt %

}

else if (status &lt ) {

% &gt

&lt hr color=#CC &gt

&lt span class=text &gt&lt font color=red size= &gt&lt center &gt&lt P &gt?¢éú′í?ó &lt /P &gt&lt /center &gt&lt /font &gt&lt /span &gt

&lt %

}

% &gt

&lt hr color=#CC &gt

&lt %

}

catch (Exception e){

outprintln(etoString());

}

% &gt

&lt /BODY &gt

&lt /HTML &gt

上一篇:在SWT中使用OLE操纵Excel(二)

下一篇:设计心得——用 XDoclet 减少代码膨胀