简体   繁体   English

使用DynamicReports API将图像渲染为XLS报告

[英]Render Image to XLS Report Using DynamicReports API

I want to render image from a folder and display in Excel report. 我想从文件夹中渲染图像并显示在Excel报表中。

Following codes used to render. 以下代码用于渲染。

String headerImagePath = "/file/fileName.jpg"
BufferedImage img = null;

try {
    img = ImageIO.read(new File(headerImagePath)); 

}  catch (IOException e)  {
    e.printStackTrace();
}
JasperReportBuilder report = report();
report.title(cmp.image(img));

But image is not showing in excel sheet. 但是图像未在Excel工作表中显示。

Any other option to render an image? 还有其他渲染图像的选择吗?

Are you sure that the image path is correct? 您确定图像路径正确吗?

You can check that easily by running: 您可以通过运行以下命令轻松地进行检查:

System.out.println(new File(headerImagePath).exists());

If this code outputs false then you need to correct the path. 如果此代码输出false则需要更正路径。

Finally got it.! 终于明白了!

You need pass the image file name as a parameter. 您需要传递图像文件名作为参数。

     parameters.put("header", headerImagePath);

Add the above parameters & it's Class to Jasper Report. 将以上参数及其Class到Jasper Report。

     report.addParameter("header", String.class);

You can add the image to report as follows 您可以按以下方式添加要报告的图像

     report.title(cmp.image(exp.jasperSyntax("($P{header})",String.class)).setDimension(50, 130));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM