SpringMvc 关于 EXCEL
2023-09-11 14:17:19 时间
概述
我在使用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");
}
}
相关文章
- SpringMVC中 -- @RequestMapping的作用及用法
- springmvc上传图片《2》
- SpringMVC之类型转换Converter
- Spring+SpringMVC+Mybatis的分布式敏捷开发系统架构
- SpringMVC集成WebSocket【使用原生API】
- SpringMVC使用Hession发布远程服务
- Python Excel自动化之 如何根据某一列快速对比两excel文件不同并输出不同内容
- Excel VLOOKUP实用教程之 10 在使用 VLOOKUP 函数时处理错误?(教程含数据excel)
- Excel VLOOKUP实用教程之 08 VLOOKUP如果实现区分大小写的查找?(教程含数据excel)
- Excel VLOOKUP实用教程之 07 vlookup如何解决肉眼看完全匹配,但是就是返回N/A错误(教程含数据excel)
- springmvc跳转到自定义错误页面的三种方法
- EXCEL excel中运用ctrl+D、ctrl+enter、ctrl+E批量填充数据
- SpringMVC创建Web工程并使用SpringSecurity进行权限控制的详细配置方法
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- springMVC 访问404
- SpringMVC访问WEB-INF下的jsp的方法
- 【springMVC】转发与重定向
- springmvc中select可以绑定enum中所有数据的方法
- springmvc中的页面解析器ViewResolver不起作用,变量输出字符串的解决方案