javajspjavascript中如何实现将统计表格保存成excel文件?
< SCRIPT LANGUAGE=JavaScript >
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< tbloutrowslength;i++)
for(j=;j< tbloutrows(i)cellslength;j++)
oSheetCells(i+ j+)Value = tbloutrows(i)cells(j)innerText
oXLVisible = true;
oXLUserControl = true;
}
< /SCRIPT >
//这个问题其实你搜一下就有了
首先你的页面上要有一个按钮save
这个按钮先做查询数据库然后action转到保存excell的页面即我给你的这些代码由于我的是用这个页面是隐藏的点击save时有跳出界面问你是打开还是保存xxxxxxxxxxxxxx是你调用数据库的记录
< %@ page contentType=text/html;charset=gb % >
< %@ page import=javalang*% >
< %
try{
responsesetContentType(Application/msexcel);
responsesetHeader(ContentDisposition attachment;filename=trainlistxls);
StringBuffer cont=new StringBuffer();
% >
< HTML >
< HEAD >
< META httpequiv=ContentStyleType content=text/css >
< /HEAD >
< BODY >
< br >< br >< br >
< %
int status = khViewBeangetStatus();
if (status == ){
int rscount = khViewBeangetRSCount();
% >
< %
contappend(< html >< head >< META content=′text/html; charset=gb′ httpequiv=ContentType >< /head >< body > );
contappend(< h > SOP??μμé?ˉ?á?< /h >);
contappend(< table width=′%′ border=′′ > );
contappend(< tr > );
contappend(< td height=′′ >???to? < /td > );
contappend(< td height=′′ >???t?? < /td > );
contappend(< td height=′′ >??? < /td > );
contappend(< td height=′′ >éúD§ê±?? < /td > );
contappend(< /tr > );
contappend(< tr > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< /tr > );
contappend(< tr > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
}
contappend(< /table > );
contappend(< /body >< /html > );
responsegetWriter()println(conttoString());
responsegetWriter()close();
% >
< %
}
else if (status > ) {
% >
< hr color=#CC >
< span class=text >< font color=blue size= >< center >< P >?Têy?Y < /P >< /center >< /font >< /span >
< %
}
else if (status < ) {
% >
< hr color=#CC >
< span class=text >< font color=red size= >< center >< P >?¢éú′í?ó < /P >< /center >< /font >< /span >
< %
}
% >
< hr color=#CC >
< %
}
catch (Exception e){
outprintln(etoString());
}
% >
< /BODY >
< /HTML >