• 大小: 61KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-16
  • 语言: 其他
  • 标签: poi  

资源简介

Spring+Mybatis+Druid+POI示例整合demo

资源截图

代码片段和文件信息

package com.mengdee.manager.controller;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.usermodel.HSSFCell;
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.hssf.util.HSSFColor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import com.mengdee.manager.domain.User;
import com.mengdee.manager.service.UserService;

@Controller
@RequestMapping(“/user“)
public class UserController {

@Autowired
private UserService userService;

@RequestMapping(“/list“)
public String getUserList(){
List userList = userService.getUserList();

for (User user : userList) {
System.out.println(user);
}

return “index“;
}

@SuppressWarnings(“resource“)
@RequestMapping(“/export“)    
    public void exportExcel(HttpServletResponse response HttpSession session String name) throws Exception {  

String[] tableHeaders = {“id“ “姓名“ “年龄“}; 

     HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(“Sheet1“);
HSSFCellstyle cellstyle = workbook.createCellstyle();    
cellstyle.setAlignment(HorizontalAlignment.CENTER);  
cellstyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellstyle.setFillPattern(FillPatternType.DIAMONDS);
cellstyle.setFillForegroundColor(HSSFColor.BLUE.index);
cellstyle.setFillBackgroundColor(HSSFColor.LIGHT_YELLOW.index);
cellstyle.setBottomBorderColor(HSSFColor.DARK_RED.index);


Font font = workbook.createFont();  
font.setColor(HSSFColor.RED.index);  
font.setBold(true);
font.setItalic(true);
font.setUnderline(HSSFFont.U_SINGLE);
cellstyle.setFont(font);

// 将第一行的三个单元格给合并
sheet.addMergedRegion(new CellRangeAddress(0 0 0 2));
HSSFRow row = sheet.createRow(0);
HSSFCell beginCell = row.createCell(0);
beginCell.setCellValue(“通讯录“);
beginCell.setCellstyle(cellstyle);


row = sheet.createRow(1);
// 创建表头
for (int i = 0; i < tableHeaders.length

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-05-31 09:30  Spring-Mybatis-Druid\
     文件        1308  2017-06-05 14:28  Spring-Mybatis-Druid\.classpath
     文件        1229  2017-05-31 10:06  Spring-Mybatis-Druid\.project
     目录           0  2017-05-31 10:06  Spring-Mybatis-Druid\.settings\
     文件         639  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\.jsdtscope
     文件         212  2017-06-05 14:16  Spring-Mybatis-Druid\.settings\org.eclipse.core.resources.prefs
     文件         430  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\org.eclipse.jdt.core.prefs
     文件          90  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\org.eclipse.m2e.core.prefs
     文件         701  2017-05-31 10:06  Spring-Mybatis-Druid\.settings\org.eclipse.wst.common.component
     文件         252  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2017-05-31 09:30  Spring-Mybatis-Druid\.settings\org.eclipse.wst.jsdt.ui.superType.name
     文件         602  2017-05-31 10:03  Spring-Mybatis-Druid\.settings\org.eclipse.wst.validation.prefs
     文件         232  2017-05-31 10:03  Spring-Mybatis-Druid\.settings\org.eclipse.wst.xsl.core.prefs
     文件        6962  2017-06-05 15:31  Spring-Mybatis-Druid\pom.xml
     目录           0  2017-05-31 09:40  Spring-Mybatis-Druid\src\
     目录           0  2017-05-31 09:40  Spring-Mybatis-Druid\src\main\
     目录           0  2017-06-03 08:53  Spring-Mybatis-Druid\src\main\java\
     目录           0  2017-05-31 09:45  Spring-Mybatis-Druid\src\main\java\com\
     目录           0  2017-05-31 09:45  Spring-Mybatis-Druid\src\main\java\com\mengdee\
     目录           0  2017-06-03 08:53  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\
     目录           0  2017-05-31 13:48  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\controller\
     文件        4916  2017-06-05 19:37  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\controller\UserController.java
     目录           0  2017-05-31 14:18  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\
     目录           0  2017-05-31 15:12  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\
     文件         395  2017-05-31 15:18  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\baseDAO.java
     文件         329  2017-06-02 16:58  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\UserDao.java
     目录           0  2017-05-31 10:08  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\impl\
     文件        1307  2017-06-02 17:12  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\impl\UserDaoImpl.java
     目录           0  2017-06-02 13:38  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\mapper\
     文件         414  2017-06-02 13:38  Spring-Mybatis-Druid\src\main\java\com\mengdee\manager\dao\user\mapper\UserEntityMapper.java
............此处省略91个文件信息

评论

共有 条评论