Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增了读图片的特性 #1316

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

新增了读图片的特性 #1316

wants to merge 7 commits into from

Conversation

dota17
Copy link
Contributor

@dota17 dota17 commented May 15, 2020

在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();
}`

@CLAassistant
Copy link

CLAassistant commented May 15, 2020

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.

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

@zhuangjiaju zhuangjiaju added the pending verification This problem needs to be confirmed label Apr 9, 2021
@zhuangjiaju
Copy link
Collaborator

zhuangjiaju commented Sep 16, 2021

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

@zhuangjiaju zhuangjiaju added the question Further information is requested label Sep 16, 2021
@liaoliang
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending verification This problem needs to be confirmed question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants