VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > Java教程 >
  • java 导入到EXCEL表格

复制代码
package com.fh.util;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.servlet.view.document.AbstractXlsView;

import com.fh.util.PageData;
import com.fh.util.Tools;

/**
 * 说明:导入到EXCEL
 * 作者:FH Admin
 * from:fhadmin.cn
 */
public class ObjectExcelView extends AbstractXlsView{
    
    @Override
    protected void buildExcelDocument(Map<String, Object> model,
            Workbook workbook, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        // TODO Auto-generated method stub
        Date date = new Date();
        String filename = Tools.date2Str(date, "yyyyMMddHHmmss");
        HSSFSheet sheet;
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition", "attachment;filename="+filename+".xls");
        
        HSSFWorkbook book = (HSSFWorkbook) workbook;
        sheet = book.createSheet("sheet1");
        
        List<String> titles = (List<String>) model.get("titles");
        int len = titles.size();
        HSSFCellStyle headerStyle = book.createCellStyle(); //标题样式
        headerStyle.setAlignment(HorizontalAlignment.CENTER);
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        HSSFFont headerFont = book.createFont();            //标题字体
        headerFont.setBold(true);
        headerFont.setFontHeightInPoints((short)11);
        headerStyle.setFont(headerFont);
        short height=25*20;
        HSSFRow row = sheet.createRow(0);
        for(int i=0; i<len; i++){ //设置标题
            String title = titles.get(i);
            row.setRowStyle(headerStyle);
            row.createCell(i).setCellValue(title);  
        }
        sheet.getRow(0).setHeight(height);
        
        HSSFCellStyle contentStyle = book.createCellStyle(); //内容样式
        contentStyle.setAlignment(HorizontalAlignment.CENTER);
        List<PageData> varList = (List<PageData>) model.get("varList");
        int varCount = varList.size();
        for(int i=0; i<varCount; i++){
            PageData vpd = varList.get(i);
            HSSFRow rows = sheet.createRow(i+1); 
            for(int j=0;j<len;j++){
                String varstr = vpd.getString("var"+(j+1)) != null ? vpd.getString("var"+(j+1)) : "";
                rows.setRowStyle(contentStyle);
                rows.createCell(j).setCellValue(varstr);
            }
            
        }
        
    }



}
 
复制代码

 ------------------------------------------------------------------自定义表单
28. 定义模版:拖拽左侧表单元素到右侧区域,编辑表单元素,保存表单模版
29. 表单模版:编辑维护表单模版,复制表单模版,修改模版类型,预览表单模版
30. 我的表单:选择表单模版,编辑表单规则,是否上传图片、附件、开启富文本、挂靠流程开关等
31. 表单数据:从我的表单进去可增删改查表单数据,修改表单规则
32. 挂靠记录:记录表单数据和流程实例ID关联记录,可删除

 

出处:

https://www.cnblogs.com/m170981362621/p/15342269.html


相关教程