1.需求: 导出图片到excel中
2. 问题:图片是存在图片服务器上,不能直接像读取本地图片那样读取图片
3. 解决方案参考网上
// 插入图片
String shopPic = storeFindVo.getShopPic();
int num = 0;
if (shopPic != null){
//获取服务器地址
String filePath = SystemConstants.getPtdImageUrl();
String[] picList = shopPic.split(",");
for (int i=0;i<picList.length;i++){
try {
byte[] data = {};
URL url = new URL(filePath + picList[i]);
//打开连接
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置请求方式为"GET"
conn.setRequestMethod("GET");
//超时响应时间为5秒
conn.setConnectTimeout(5 * 1000);
//通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
data = readInputStream(inStream);
if (i == 0){
exportMap.put("shopPic",data);
}else{
exportMap.put(""+num,data);
if (!arrayList.contains(""+num)){
arrayList.add(""+num);
}
}
num ++;
} catch (Exception e) {
e.printStackTrace();
}
}
}else {
exportMap.put("shopPic","");
}
4.效果如下