在使用jxl导出excel(带边栏合并)我写了关于jxl写excel(带单元格合并)的内容。
当初之所以选择jxl,是因为jxl在纯数据文档的读写性能方面很有优势,可是它不支持excel2007,不得不说是一个很大的遗憾。
因此,本人决定再用POI完成相同的功能。
Run.java
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
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.ss.util.CellRangeAddress;
import org.apache.poi.hssf.util.HSSFColor;
public class Run {
public static void main(String[] args) throws IOException {
CreateData data = new CreateData();
List excelList = data.getData();
FileOutputStream fos = new FileOutputStream("D:\\myfile.xls");
HSSFWorkbook wb = new HSSFWorkbook();
//边栏单元格字体
HSSFFont headerFont = wb.createFont();
//ARIAL字体
headerFont.setFontName(HSSFFont.FONT_ARIAL);
//10号
headerFont.setFontHeightInPoints((short)10);
//粗体
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
//边栏单元格样式
HSSFCellStyle headerStyle = wb.createCellStyle();
headerStyle.setFont(headerFont);
//垂直 居中
headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
//水平 居中
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//左右上下边框样式
headerStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
headerStyle.setBorderRight(HSSFCellSt