1、代码
package com.li.zzh.fileUtils;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;
@Component
public class ExcelUtils {
@Override
@Transactional
public Workbook createExcelModel(String title){
//两百条刷新磁盘一次
Workbook workbook = new SXSSFWorkbook(200);
//生成一个表格
Sheet sheet = workbook.createSheet("托书");
//创建excel表格
for(int i = 0; i < 3; i++){
//创建行
Row row = sheet.createRow((int)i);
//创建行对应的列
Cell cell = row.createCell(0);
if(i == 0){
cell.setCellValue("FBA仓库代码");
}else if(i == 1){
cell.setCellValue("收件人邮编");
}else if(i == 2){
cell.setCellValue("物流方式");
}
//创建五个单元格(此五个单元格需合并成一个)
for(int j = 1; j < 6; j++){
cell = row.createCell(j);
if(i==0 && j == 1){
cell.setCellValue("01");
}else if(i==1 && j == 1){
cell.setCellValue("11");
}else if(i==2 && j == 1){
cell.setCellValue("21");
}
}
cell = row.createCell(6);
if(i == 0){
cell.setCellValue("收件人地址");
}else if(i == 1){
cell.setCellValue("收件人城市");
}else if(i == 2){
cell.setCellValue("是否单独报关");
}
//创建五个单元格(此五个单元格需合并成一个)
for(int j = 7; j < 12; j++){
cell = row.createC