皕杰报表可以用自定义函数来获取URL路径图片,然后将图片流返回到图片单元格中,最后预览的时候显示图片 。
方案:
1.参考皕杰帮助文档-开发指南-javadoc-bios.report.api.customize.CustomFunction,写自定义函数,实现获取网络图片流
实例代码:
package bios.report.dev.examples.function;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import bios.report.api.customize.CustomFunction;
import bios.report.api.utils.LoggerUtil;
public class UrlImage extends CustomFunction {
public Object calc(Object[] args) {
String imageUrl = (String)args[0];
try {
URL url = new URL(imageUrl);
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
urlc.setRequestMethod("GET");
InputStream in = urlc.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] tmp = new byte[1024];
int i;
while ((i = in.read(tmp)) >= 0) {
out.write(tmp, 0, i);
return out.toByteArray(); //将图片转为二进制数据数组返回
} catch (Exception e) {
LoggerUtil.error("图片获取失败", e); //在报表日志中输出错误信息
return null;
2.将这个自定义函数类打成jar包UrlImage.jar。
3.设计器-窗口-首选项-通用配置-类加载,将这个jar包加载进来
4.配置自定义函数路径,设计器-工具-自定义函数
5.设计报表,单元格为图片单元格,单元格表达式为=urlimg("https://pics3.baidu.com/feed/b2de9c82d158ccbffdfb7ab367a41c36b035417d.jpeg?token=5d0fe0128007efa48245845905eb28c0")
图片路径为网上随意抓取
6.预览报表
7.Web端集成自定义函数
将设计器BIOS Studio\configuration文件夹下的custom_functions.properties文件复制到web应用报表环境WEB-INF\resources文件夹下 ,将自定义函数jar包复制到web应用报表环境WEB-INF\lib文件夹下 。
特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。
Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.