|
@@ -19,6 +19,7 @@ import java.util.Map;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.util.HSSFColor;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
import org.apache.poi.ss.usermodel.Comment;
|
|
@@ -180,6 +181,7 @@ public class ExportExcel {
|
|
|
public ExportExcel(String title, List<String> headerList) {
|
|
|
initialize(title, headerList);
|
|
|
}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 初始化函数
|
|
@@ -187,7 +189,7 @@ public class ExportExcel {
|
|
|
* @param headerList 表头列表
|
|
|
*/
|
|
|
private void initialize(String title, List<String> headerList) {
|
|
|
- this.wb = new SXSSFWorkbook(500);
|
|
|
+ this.wb = new SXSSFWorkbook(700);
|
|
|
this.sheet = wb.createSheet("Export");
|
|
|
this.styles = createStyles(wb);
|
|
|
// Create title
|
|
@@ -205,9 +207,39 @@ public class ExportExcel {
|
|
|
throw new RuntimeException("headerList not null!");
|
|
|
}
|
|
|
Row headerRow = sheet.createRow(rownum++);
|
|
|
- headerRow.setHeightInPoints(16);
|
|
|
+ headerRow.setHeightInPoints(30);
|
|
|
+ Row headerRow1 = sheet.createRow(rownum++);
|
|
|
+ headerRow1.setHeightInPoints(30);
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(1, 0, 0, 0));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(1, 0, 1, 1));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 3, 3));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 4, 5));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 7, 8));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 9, 9));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 10, 10));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 11, 11));
|
|
|
+ sheet.setColumnWidth(0, 2000);
|
|
|
+ sheet.setColumnWidth(1, 3000);
|
|
|
+ sheet.setColumnWidth(2, 2000);
|
|
|
+ sheet.setColumnWidth(3, 12000);
|
|
|
+ sheet.setColumnWidth(4, 2000);
|
|
|
+ sheet.setColumnWidth(5, 2000);
|
|
|
+ sheet.setColumnWidth(6, 2000);
|
|
|
+ sheet.setColumnWidth(7, 2000);
|
|
|
+ sheet.setColumnWidth(8, 3000);
|
|
|
+ sheet.setColumnWidth(9, 3000);
|
|
|
+ sheet.setColumnWidth(10, 3000);
|
|
|
+ sheet.setColumnWidth(11, 3000);
|
|
|
+ Cell tempCell1 = headerRow.createCell(4);
|
|
|
+ tempCell1.setCellValue("建筑工程费");
|
|
|
+ tempCell1.setCellStyle(styles.get("header"));
|
|
|
+ Cell tempCell = headerRow.createCell(7);
|
|
|
+ tempCell.setCellStyle(styles.get("header"));
|
|
|
+ tempCell.setCellValue("安装工程费");
|
|
|
for (int i = 0; i < headerList.size(); i++) {
|
|
|
- Cell cell = headerRow.createCell(i);
|
|
|
+ Cell cell = headerRow1.createCell(i);
|
|
|
cell.setCellStyle(styles.get("header"));
|
|
|
String[] ss = StringUtils.split(headerList.get(i), "**", 2);
|
|
|
if (ss.length==2){
|
|
@@ -221,12 +253,17 @@ public class ExportExcel {
|
|
|
}
|
|
|
sheet.autoSizeColumn(i);
|
|
|
}
|
|
|
- for (int i = 0; i < headerList.size(); i++) {
|
|
|
+ for (int i = 0; i < headerList.size(); i++) {
|
|
|
int colWidth = sheet.getColumnWidth(i)*2;
|
|
|
- sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
|
|
|
+ sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
|
|
|
}
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(1, 0, 1, 1));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(1, 0, 2, 2));
|
|
|
+// sheet.addMergedRegion(new CellRangeAddress(1, 0, 3, 3));
|
|
|
log.debug("Initialize success.");
|
|
|
}
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 创建表格样式
|
|
@@ -285,22 +322,16 @@ public class ExportExcel {
|
|
|
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
|
|
Font headerFont = wb.createFont();
|
|
|
headerFont.setFontName("Arial");
|
|
|
- headerFont.setFontHeightInPoints((short) 10);
|
|
|
+ headerFont.setFontHeightInPoints((short) 15);
|
|
|
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
|
|
- headerFont.setColor(IndexedColors.WHITE.getIndex());
|
|
|
+ headerFont.setColor(IndexedColors.BLACK.getIndex());
|
|
|
style.setFont(headerFont);
|
|
|
styles.put("header", style);
|
|
|
-
|
|
|
return styles;
|
|
|
}
|
|
|
|
|
|
|
|
|
-// private Map<String, CellStyle> createStyles(Workbook wb) {
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 添加一行
|