zoukankan      html  css  js  c++  java
  • SpringMvc 关于 EXCEL

    概述
    我在使用SpingMvc 的EXCEL的发现传统的

    • AbstractJExcelView jexcel api已经过时
    • AbstractView poi Api
      通过阅读官方文档发现建议我们使用
    • AbstractXlsView
    • AbstractXlsxView
    • AbstractXlsxStreamingView
    
    Deprecated.  as of Spring 4.2, in favor of AbstractXlsView and its AbstractXlsxView and AbstractXlsxStreamingView variants
    
    Convenient superclass for Excel document views. Compatible with Apache POI 3.5 and higher, as of Spring 4.0. 
    
    Properties: 
    •url (optional): The url of an existing Excel document to pick as a starting point. It is done without localization part nor the ".xls" extension. 
    • 这里我们写一个例子:
    package myview;
    
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.springframework.stereotype.Component;
    import org.springframework.web.servlet.view.document.AbstractXlsView;
    
    @Component
    public class MyExcelView extends AbstractXlsView {
        /**
         * AbstractJExcelView  jexcel api已经过时
         * AbstractView  poi Api
         * 简单定义的显示excel数据内容
         */
        @Override
        protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request,
                HttpServletResponse response) throws Exception {
            response.setHeader("content-disposition", "attachment;filename=我的工作簿.xls");
            Sheet sheet = workbook.createSheet("我的工作簿");
            Row row = sheet.createRow(0);
            Cell cell = row.createCell(0);
            Cell cell2 = row.createCell(1);
            cell.setCellValue("1");
            cell2.setCellValue("2");
        }
    }
    
  • 相关阅读:
    java代码连接数据库
    phpcms v9 读取地区联动菜单缓存文件
    PHPCMS V9二次开发便捷自定义后台入口文件夹
    phpcms v9中模板标签使用及联动菜单
    Phpcms v9系统类库与函数库调用方法
    phpcms v9 二次开发
    phpcms v9开源开发框架基础mvc解读
    phpcms插件开发初步规范
    phpcms v9二次开发之模型类的应用(1)
    phpcms v9二次开发之模型类的应用(2)
  • 原文地址:https://www.cnblogs.com/dgwblog/p/7635186.html
Copyright © 2011-2022 走看看