public void insertImage(HSSFWorkbook workbook,HSSFSheet sheet){
try {
InputStream inputStream = new FileInputStream("\\img\\logo.png");
byte[] imageBytes = IOUtils.toByteArray(inputStream);
int pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG);
inputStream.close();
CreationHelper helper = workbook.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(0);
Picture pict = drawing.createPicture(an`enter code here`chor, pictureureIdx);
pict.resize(0.4);
}catch (Exception e) {
System.out.println(e);
}
}
这是我在excel文件中插入徽标图片的java代码。我想从“http://localhost:8080/Enertech/img/logo.png”这样的URL传递路径 如何重写上面的代码。请帮帮我。
答案 0 :(得分:0)
您是否尝试从网址获取流?只需尝试更改一行并检查。
InputStream input = new URL("http://localhost:8080/Enertech/img/logo.png").openStream();