easyexcel icon indicating copy to clipboard operation
easyexcel copied to clipboard

新增了读图片的特性

Open dota17 opened this issue 4 years ago • 3 comments

在excel07格式的文件中图片的数据和单元格的数据是分开存放的,所以在读的时候也是分开读。用户可以先读图片的数据,将图片数据保存在List<ImageData>中,然后再读单元格的数据,最后再把单元格数据和图片数据进行对应。

ImageData中保存了图片所在sheet的名字、index、在sheet中的坐标、图片类型、图片数据等信息。

代码可能还有不完善的地方,欢迎提出意见

用法: /** * 使用文件名读图片信息,默认读所有sheet中的图片,图片数据放在imageDataList中 */ @Test public void readImageWithFileNameTest() throws IOException { String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx"; ArrayList<ImageData> imageDataList = new ArrayList<ImageData>(); ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList); EasyExcel.readImage(fileName, imageDataReadListener); }

/**
 * 使用输入流读图片信息,默认读所有sheet中的图片,图片数据放在imageDataList中
 */
@Test
public void readImageWithStreamTest() throws IOException {
    String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx";
    ArrayList<ImageData> imageDataList = new ArrayList<ImageData>();
    ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList);
    File imageFile = new File(fileName);
    InputStream in = new FileInputStream(imageFile);
    EasyExcel.readImage(in, 1, imageDataReadListener);
    in.close();
}

/**
 * 使用文件名读指定sheet图片信息,图片数据放在imageDataList中
 */
@Test
public void readImageWithSheetNameTest() throws IOException {
    String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx";
    ArrayList<ImageData> imageDataList = new ArrayList<ImageData>();
    ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList);

    EasyExcel.readImage(fileName, "image1", imageDataReadListener);
}

/**
 * 使用输入流读指定sheet图片信息,图片数据放在imageDataList中
 */
@Test
public void readImageWithSheetNameTest1() throws IOException {
    String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx";
    ArrayList<ImageData> imageDataList = new ArrayList<ImageData>();
    ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList);
    File imageFile = new File(fileName);
    InputStream in = new FileInputStream(imageFile);

    EasyExcel.readImage(in, "image1", imageDataReadListener);
    in.close();
}

/**
 * 使用文件名读指定索引的sheet中的图片信息,图片数据放在imageDataList中
 */
@Test
public void readImageWithSheetNoTest() throws IOException {
    String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx";
    ArrayList<ImageData> imageDataList = new ArrayList<ImageData>();
    ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList);

    EasyExcel.readImage(fileName, 2, imageDataReadListener);
}

/**
 * 使用输入流读指定索引的sheet中的图片信息,图片数据放在imageDataList中
 */
@Test
public void readImageWithSheetNoTest1() throws IOException {
    String fileName = TestFileUtil.getPath() + "demo" + File.separator + "imageRead.xlsx";
    ArrayList<ImageData> imageDataList = new ArrayList<ImageData>();
    ImageDataReadListener imageDataReadListener = new ImageDataReadListener(imageDataList);
    File imageFile = new File(fileName);
    InputStream in = new FileInputStream(imageFile);

    EasyExcel.readImage(in, 2, imageDataReadListener);
    in.close();
}`

dota17 avatar May 15 '20 11:05 dota17

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

:x: zhuangjiaju
:x: dota17
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 15 '20 11:05 CLAassistant

感觉没有支持03版呀 这个感觉略坑…… 然后代码有点读 有点方

zhuangjiaju avatar Sep 16 '21 08:09 zhuangjiaju

没有excel带图的数据读取呀 怎么搞

liaoliang avatar Nov 09 '21 14:11 liaoliang