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");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值