1. 程式人生 > >java pageoffice使用,生成匯出excel報表

java pageoffice使用,生成匯出excel報表

web.xml的配置

<!-- PageOffice Begin -->
<servlet>
<servlet-name>poserver</servlet-name>
<servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/poserver.zz</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/poserver.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/pageoffice.cab</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/popdf.cab</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/sealsetup.exe</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>poserver</servlet-name>
<url-pattern>/posetup.exe</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>adminseal</servlet-name>
<servlet-class>com.zhuozhengsoft.pageoffice.poserver.AdminSeal</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/adminseal.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/loginseal.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>adminseal</servlet-name>
<url-pattern>/sealimage.do</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>mht</extension>
<mime-type>message/rfc822</mime-type>
</mime-mapping>
<context-param>
<param-name>adminseal-password</param-name>
<param-value>111111</param-value>
</context-param>
<!-- PageOffice End -->


後臺java程式碼

public String entrustMonthSum(HttpServletRequest request,String sdate,String edate) {

UserFormMap user = (UserFormMap) Common.findUserSession(request);
String orgid="0";
if(null!=user){
orgid = String.valueOf(user.get("orgid"));
}
 
if (Common.isEmpty(sdate)) {
Date date= new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-01");
sdate=sdf.format(date);
}
 
if (Common.isEmpty(edate)) {
edate="3000-12-31";
}
 
List<Map<String, String>> list = surveyDistributMapper.getEntrustMonthSum(sdate, edate,orgid);

PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
poCtrl1.setServerPage(request.getContextPath()+"/poserver.zz"); //此行必須
Workbook workBook = new Workbook();
Sheet sheet = workBook.openSheet("Sheet1");
Table table = sheet.openTable("A3:H3");
    for(int i=0; i< list.size(); i++)
    { 
//向excel填充資料
    Map<String, String> map=list.get(i);
        table.getDataFields().get(0).setValue(map.get("create_time"));
        table.getDataFields().get(1).setValue(map.get("address")!=null?map.get("address"):"");
        table.getDataFields().get(2).setValue(map.get("intermediary_name")!=null?map.get("intermediary_name"):"");
        table.getDataFields().get(3).setValue(map.get("bank")!=null?map.get("bank"):"");
        table.getDataFields().get(4).setValue(map.get("subbank")!=null?map.get("subbank"):"");
        table.getDataFields().get(5).setValue(map.get("evaluateType")!=null?map.get("evaluateType"):"");
        table.getDataFields().get(6).setValue(map.get("orgname")!=null?map.get("orgname"):"");
        table.getDataFields().get(7).setValue(map.get("isover"));
        
        table.nextRow();
    }
    table.close();
    
poCtrl1.setWriter(workBook);

//隱藏選單欄
poCtrl1.setMenubar(false);
//隱藏工具欄
//poCtrl1.setCustomToolbar(false);
poCtrl1.setOfficeToolbars(false);
poCtrl1.addCustomToolButton("儲存", "SaveDocuments()", 1);//SaveDocuments與jsp頁面中的js函式名字一致,數字代表的是對應的圖示  
        poCtrl1.addCustomToolButton("-", "", 0);  
        poCtrl1.addCustomToolButton("列印", "ShowPrintDlg()", 6);  
        poCtrl1.addCustomToolButton("-", "", 0);  
        poCtrl1.addCustomToolButton("全屏切換", "SetFullScreen()", 4);  
        poCtrl1.addCustomToolButton("-", "", 0);  
        poCtrl1.addCustomToolButton("加蓋印章", "AddSeal()", 5);  
        poCtrl1.addCustomToolButton("手寫籤批", "AddHandSign()", 5);  
        poCtrl1.addCustomToolButton("驗證印章", "VerifySeal()", 5);  
        poCtrl1.setSaveFilePage("saveword.action");//儲存需要執行的的action  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
poCtrl1.webOpen(basePath+"doc/wtbb.xlsx", OpenModeType.xlsNormalEdit, String.valueOf(user.get("userName")));//excel模板
poCtrl1.setTagId("PageOfficeCtrl1"); //此行必須和前端中的<po:PageOfficeCtrl id="PageOfficeCtrl1" />id保持一致 


return "view/excel/excel";//返回的jsp
}


jsp:excel.jsp

<%@ page language="java"
import="java.util.*,com.zhuozhengsoft.pageoffice.*,com.zhuozhengsoft.pageoffice.excelwriter.*"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.pageoffice.cn" prefix="po"%>




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
</head>
<body>
    <script type="text/javascript">
        function SaveDocument() {
            document.getElementById("PageOfficeCtrl1").ShowDialog(3);
            
        }
    </script>
    <form id="form1">
    <div style=" width:100%; height:700px;">
        <po:PageOfficeCtrl id="PageOfficeCtrl1">
        </po:PageOfficeCtrl>
    </div>
    </form>
</body>
</html>