Skip to content

Commit

Permalink
新增大文件读取案例
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Feb 8, 2023
1 parent 14cc4d7 commit 7fac3bf
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,51 @@ public void imageWritePoi() throws Exception {
fileOutputStream.flush();
workbook.close();
}

@Test
public void tep() throws Exception {
String file = "/Users/zhuangjiaju/test/imagetest" + System.currentTimeMillis() + ".xlsx";
SXSSFWorkbook workbook = new SXSSFWorkbook();
SXSSFSheet sheet = workbook.createSheet("测试");
CreationHelper helper = workbook.getCreationHelper();
SXSSFDrawing sxssfDrawin = sheet.createDrawingPatriarch();

byte[] imagebyte = FileUtils.readFileToByteArray(new File("/Users/zhuangjiaju/Documents/demo.jpg"));

for (int i = 0; i < 1 * 10000; i++) {
SXSSFRow row = sheet.createRow(i);
SXSSFCell cell = row.createCell(0);
cell.setCellValue(i);
int pictureIdx = workbook.addPicture(imagebyte, Workbook.PICTURE_TYPE_JPEG);
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(i);
// 插入图片
Picture pict = sxssfDrawin.createPicture(anchor, pictureIdx);
pict.resize();
log.info("新增行:{}", i);
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
fileOutputStream.flush();
workbook.close();
}

@Test
public void large() throws Exception {
String file = "/Users/zhuangjiaju/test/imagetest" + System.currentTimeMillis() + ".xlsx";
SXSSFWorkbook workbook = new SXSSFWorkbook(new XSSFWorkbook(
new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/src/test/resources/large/large07.xlsx")));
SXSSFSheet sheet = workbook.createSheet("测试");

SXSSFRow row = sheet.createRow(500000);
SXSSFCell cell = row.createCell(0);
cell.setCellValue("test");

FileOutputStream fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
fileOutputStream.flush();
workbook.close();

}
}

0 comments on commit 7fac3bf

Please sign in to comment.