use of com.alibaba.excel.ExcelWriter in project springboot-demo by small-rose.
the class ExcelWriteDemo01 method demo03.
@Test
public void demo03() {
// 写法3
String fileName = TestFileUtil.getPath() + "simpleWrite" + datetime() + ".xlsx";
// 这里 需要指定写用哪个class去写
ExcelWriter excelWriter = null;
try {
excelWriter = EasyExcel.write(fileName, DoorData.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet("sheet1").build();
excelWriter.write(data(), writeSheet);
} finally {
// 千万别忘记finish 会帮忙关闭流
if (excelWriter != null) {
excelWriter.finish();
}
}
}
use of com.alibaba.excel.ExcelWriter in project springboot-demo by small-rose.
the class ExcelFacadeService method addColumnInfos.
private void addColumnInfos(String schema, String fileName, List<TableInfo> allTables) {
if (allTables.isEmpty()) {
log.info(" allTables size is 0 ");
}
int index = 2;
for (TableInfo tableInfo : allTables) {
if (index == 4) {
break;
}
ExcelWriter excelWriter = EasyExcel.write(fileName, TableColumn.class).build();
List<TableColumn> columnInfos = oracleSelectService.getColumnInfo(schema, tableInfo.getTableName());
WriteSheet writeSheet = EasyExcel.writerSheet(index, tableInfo.getTableName()).head(TableColumn.class).build();
excelWriter.write(columnInfos, writeSheet);
excelWriter.finish();
index++;
}
System.out.println("=====执行完成=====");
}
use of com.alibaba.excel.ExcelWriter in project study by bage2014.
the class WriteTest method tableWrite.
/**
* 使用table去写入
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 然后写入table即可
*/
@Test
public void tableWrite() {
String fileName = TestFileUtil.getPath() + "tableWrite" + System.currentTimeMillis() + ".xlsx";
// 这里直接写多个table的案例了,如果只有一个 也可以直一行代码搞定,参照其他案例
// 这里 需要指定写用哪个class去写
ExcelWriter excelWriter = EasyExcel.write(fileName, DemoData.class).build();
// 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
WriteSheet writeSheet = EasyExcel.writerSheet("模板").needHead(Boolean.FALSE).build();
// 这里必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
WriteTable writeTable0 = EasyExcel.writerTable(0).needHead(Boolean.TRUE).build();
WriteTable writeTable1 = EasyExcel.writerTable(1).needHead(Boolean.TRUE).build();
// 第一次写入会创建头
excelWriter.write(data(), writeSheet, writeTable0);
// 第二次写如也会创建头,然后在第一次的后面写入数据
excelWriter.write(data(), writeSheet, writeTable1);
// / 千万别忘记finish 会帮忙关闭流
excelWriter.finish();
}
use of com.alibaba.excel.ExcelWriter in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method writeExcelToOutput.
private void writeExcelToOutput(List<ExcelRuleMetric> excelRuleMetrics, OutputStream outputStream) throws WriteExcelException, IOException {
try {
LOGGER.info("Start to write metric excel");
ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLSX, true);
Sheet templateSheet = new Sheet(1, 0, ExcelRuleMetric.class);
templateSheet.setSheetName(ExcelSheetName.RULE_METRIC_NAME);
writer.write(excelRuleMetrics, templateSheet);
writer.finish();
LOGGER.info("Finish to write metric excel");
} catch (Exception e) {
throw new WriteExcelException(e.getMessage());
} finally {
outputStream.close();
}
}
use of com.alibaba.excel.ExcelWriter in project excel-spring-boot-starter by pig-mesh.
the class SingleSheetWriteHandler method write.
@Override
public void write(Object obj, HttpServletResponse response, ResponseExcel responseExcel) {
List<?> list = (List<?>) obj;
ExcelWriter excelWriter = getExcelWriter(response, responseExcel);
// 有模板则不指定sheet名
Class<?> dataClass = list.get(0).getClass();
WriteSheet sheet = this.sheet(responseExcel.sheets()[0], dataClass, responseExcel.template(), responseExcel.headGenerator());
excelWriter.write(list, sheet);
excelWriter.finish();
}
Aggregations