静态报表真的很头痛哦,查找很久发现JXL、POI在读取excel中自制的统计图表方面存在局限,无法读取;但在读取一张图片以及写入图表方面还可以,我的问题解决不了了,肿么办??????
java如何读取excel中自制的统计图表,然后将读到的图表生成 png格式的图片???
注:图表可能是一个完整的模板,也可能是通过excel中多个图表工具组合成的复合图表
希望能帮我的朋友给我发邮件,提供解决方法,不胜感激!邮箱:a303313655@163.com
在网站查找中发现通过POI获取图片在excel中的位置的博客,觉得思路很好,现转载一下,大家分享!
获取位置:
public static List getAllPictures(HSSFWorkbook workbook) {
List list = new ArrayList();
List pictureList = workbook.getAllPictures();
List clientAnchorRecords = getClientAnchorRecords(workbook);
if (pictureList.size() != clientAnchorRecords.size()) {
throw new RuntimeException("解析文件中的图片信息出错,找到的图片数量和图片位置信息数量不匹配");
}
for (int i = 0; i < pictureList.size(); i++) {
HSSFPictureData pictureData = pictureList.get(i);
ClientAnchorInfo anchor = clientAnchorRecords.get(i);
HSSFSheet sheet = anchor.sheet;
EscherClientAnchorRecord clientAnchorRecord = anchor.clientAnchorRecord;
list.add(new MyPictureData(workbook, sheet, pictureData, clientAnchorRecord));
}
return list ;
}
private static class ClientAnchorInfo {
public HSSFSheet sheet;
public EscherClientAnchorRecord clientAnchorRecord;
public ClientAnchorInfo(HSSFSheet sheet, EscherClientAnchorRecord clientAnchorRecord) {
super();
this.sheet = sheet;
this.clientAnchorRecord = clientAnchorRecord;
}
}