use of com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy in project easyexcel by alibaba.
the class AbstractWriteHolder method dealOnceAbsoluteMerge.
private void dealOnceAbsoluteMerge(List<WriteHandler> handlerList) {
OnceAbsoluteMergeProperty onceAbsoluteMergeProperty = getExcelWriteHeadProperty().getOnceAbsoluteMergeProperty();
if (onceAbsoluteMergeProperty == null) {
return;
}
handlerList.add(new OnceAbsoluteMergeStrategy(onceAbsoluteMergeProperty));
}
use of com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy in project easyexcel by alibaba.
the class FillTempTest method complexFill.
/**
* 复杂的填充
*
* @since 2.1.1
*/
@Test
public void complexFill() {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量
OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(2, 2, 0, 1);
String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).registerWriteHandler(onceAbsoluteMergeStrategy).withTemplate(TestFileUtil.readUserHomeFile("test/simple.xlsx")).build();
WriteSheet writeSheet0 = EasyExcel.writerSheet(0).build();
WriteSheet writeSheet1 = EasyExcel.writerSheet(1).build();
excelWriter.fill(teamp(), writeSheet0);
excelWriter.fill(teamp(), writeSheet1);
Map<String, Object> map = new HashMap<String, Object>();
map.put("date", "2019年10月9日13:28:28");
map.put("total", 1000);
excelWriter.fill(map, writeSheet0);
excelWriter.finish();
}
use of com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy in project easyexcel by alibaba.
the class StyleDataTest method readAndWrite.
private void readAndWrite(File file) throws Exception {
SimpleColumnWidthStyleStrategy simpleColumnWidthStyleStrategy = new SimpleColumnWidthStyleStrategy(50);
SimpleRowHeightStyleStrategy simpleRowHeightStyleStrategy = new SimpleRowHeightStyleStrategy((short) 40, (short) 50);
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
headWriteCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
WriteFont headWriteFont = new WriteFont();
headWriteFont.setFontHeightInPoints((short) 20);
headWriteFont.setColor(IndexedColors.DARK_YELLOW.getIndex());
headWriteCellStyle.setWriteFont(headWriteFont);
WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
contentWriteCellStyle.setFillForegroundColor(IndexedColors.TEAL.getIndex());
WriteFont contentWriteFont = new WriteFont();
contentWriteFont.setFontHeightInPoints((short) 30);
contentWriteFont.setColor(IndexedColors.DARK_TEAL.getIndex());
contentWriteCellStyle.setWriteFont(contentWriteFont);
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
OnceAbsoluteMergeStrategy onceAbsoluteMergeStrategy = new OnceAbsoluteMergeStrategy(2, 2, 0, 1);
EasyExcel.write(file, StyleData.class).registerWriteHandler(simpleColumnWidthStyleStrategy).registerWriteHandler(simpleRowHeightStyleStrategy).registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(onceAbsoluteMergeStrategy).sheet().doWrite(data());
EasyExcel.read(file, StyleData.class, new StyleDataListener()).sheet().doRead();
Workbook workbook = WorkbookFactory.create(file);
Sheet sheet = workbook.getSheetAt(0);
Assert.assertEquals(50 * 256, sheet.getColumnWidth(0), 0);
Row row0 = sheet.getRow(0);
Assert.assertEquals(800, row0.getHeight(), 0);
Cell cell00 = row0.getCell(0);
Assert.assertArrayEquals(new byte[] { -1, -1, 0 }, StyleTestUtils.getFillForegroundColor(cell00));
Assert.assertArrayEquals(new byte[] { -128, -128, 0 }, StyleTestUtils.getFontColor(cell00, workbook));
Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell00, workbook));
Cell cell01 = row0.getCell(1);
Assert.assertArrayEquals(new byte[] { -1, -1, 0 }, StyleTestUtils.getFillForegroundColor(cell01));
Assert.assertArrayEquals(new byte[] { -128, -128, 0 }, StyleTestUtils.getFontColor(cell01, workbook));
Assert.assertEquals(20, StyleTestUtils.getFontHeightInPoints(cell01, workbook));
Row row1 = sheet.getRow(1);
Assert.assertEquals(1000, row1.getHeight(), 0);
Cell cell10 = row1.getCell(0);
Assert.assertArrayEquals(new byte[] { 0, -128, -128 }, StyleTestUtils.getFillForegroundColor(cell10));
Assert.assertArrayEquals(new byte[] { 0, 51, 102 }, StyleTestUtils.getFontColor(cell10, workbook));
Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell10, workbook));
Cell cell11 = row1.getCell(1);
Assert.assertArrayEquals(new byte[] { 0, -128, -128 }, StyleTestUtils.getFillForegroundColor(cell11));
Assert.assertArrayEquals(new byte[] { 0, 51, 102 }, StyleTestUtils.getFontColor(cell11, workbook));
Assert.assertEquals(30, StyleTestUtils.getFontHeightInPoints(cell11, workbook));
}
Aggregations