use of com.alibaba.excel.ExcelWriter in project notes by menhuan.
the class OnirigiFrontApp1liactionTest method test1.
@Test
public void test1() throws FileNotFoundException {
OutputStream out = new FileOutputStream("F:/vscode/78.xlsx");
try {
ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
// 写第一个sheet, sheet1 数据全是List<String> 无模型映射关系
Sheet sheet1 = new Sheet(1, 0, CustomerMessage.class);
writer.write(getData(), sheet1);
writer.finish();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.alibaba.excel.ExcelWriter in project SpringBoot-Hello by ruiyeclub.
the class ExcelUtil method writeExcel.
/**
* @param outputStream Excel的输出流
* @param data 要写入的以 模型 为单位的数据
* @param clazz 模型的类
* @param excelTypeEnum Excel的格式(XLS或XLSX)
* @Description: 使用模型来写入Excel,单sheet,单table
* @Date: 2020/1/16 21:43
* @Return: byte[]
* @Throws: Exception
*/
public static void writeExcel(OutputStream outputStream, List<? extends BaseRowModel> data, Class<? extends BaseRowModel> clazz, ExcelTypeEnum excelTypeEnum) throws Exception {
// 这里指定需要表头,因为model通常包含表头信息
ExcelWriter writer = new ExcelWriter(outputStream, excelTypeEnum, true);
// 写第一个sheet, sheet1 数据全是List<String> 无模型映射关系
Sheet sheet1 = new Sheet(1, 0, clazz);
writer.write(data, sheet1);
writer.finish();
}
use of com.alibaba.excel.ExcelWriter in project SpringBoot-Hello by ruiyeclub.
the class ExcelUtil method writeExcel.
/**
* @param outputStream Excel的输出流
* @param sheetName sheet名集合
* @param datas 要写入的以 模型 为单位的数据
* @param clazzs 模型的类
* @param excelTypeEnum Excel的格式(XLS或XLSX)
* @Description: 使用模型来写入Excel,多sheet,单table (返回字节数组)
* @Date: 2020/1/16 21:43
* @Return: byte[]
* @Throws: Exception
*/
public static byte[] writeExcel(ByteArrayOutputStream outputStream, List<String> sheetName, List<List<? extends BaseRowModel>> datas, List<Class<? extends BaseRowModel>> clazzs, ExcelTypeEnum excelTypeEnum) throws Exception {
// 这里指定需要表头,因为model通常包含表头信息
ExcelWriter writer = new ExcelWriter(outputStream, excelTypeEnum, true);
if (sheetName.size() != datas.size() || datas.size() != clazzs.size()) {
throw new ArrayIndexOutOfBoundsException();
}
int i = 0;
// 写第一个sheet, sheet1 数据全是List<String> 无模型映射关系
for (String name : sheetName) {
Sheet sheet1 = new Sheet(1, 0, clazzs.get(i));
sheet1.setSheetName(name);
writer.write(datas.get(i), sheet1);
}
writer.finish();
return outputStream.toByteArray();
}
use of com.alibaba.excel.ExcelWriter in project SpringBoot-Hello by ruiyeclub.
the class ExcelUtil method writeExcel.
/**
* @param outputStream Excel的输出流
* @param data 要写入的以StringList为单位的数据
* @param table 配置Excel的表的属性
* @param excelTypeEnum Excel的格式(XLS或XLSX)
* @Description: 使用StringList来写入Excel,单sheet,单table
* @Date: 2020/1/16 21:42
* @Return: void
* @Throws: Exception
*/
public static void writeExcel(OutputStream outputStream, List<List<String>> data, Table table, ExcelTypeEnum excelTypeEnum) throws Exception {
// 这里指定不需要表头,因为String通常表头已被包含在data里
ExcelWriter writer = new ExcelWriter(outputStream, excelTypeEnum, false);
// 写第一个sheet, sheet1 数据全是List<String> 无模型映射关系,无表头
Sheet sheet1 = new Sheet(0, 0);
writer.write0(data, sheet1, table);
writer.finish();
}
use of com.alibaba.excel.ExcelWriter in project SpringBoot-Hello by ruiyeclub.
the class ExcelUtil method writeExcel.
/**
* @param outputStream Excel的输出流
* @param data 要写入的以StringList为单位的数据
* @param table 配置Excel的表的属性
* @param excelTypeEnum Excel的格式(XLS或XLSX)
* @Description: 使用StringList来写入Excel,单sheet,单table(返回byte数组)
* @Date: 2020/1/16 21:43
* @Return: byte[]
* @Throws: Exception
*/
public static byte[] writeExcel(ByteArrayOutputStream outputStream, List<List<String>> data, Table table, ExcelTypeEnum excelTypeEnum) throws Exception {
// 这里指定不需要表头,因为String通常表头已被包含在data里
ExcelWriter writer = new ExcelWriter(outputStream, excelTypeEnum, false);
// 写第一个sheet, sheet1 数据全是List<String> 无模型映射关系,无表头
Sheet sheet1 = new Sheet(0, 0);
writer.write0(data, sheet1, table);
writer.finish();
return outputStream.toByteArray();
}
Aggregations