try {
InputStream iss = new FileInputStream("D:\test.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(iss);
XSSFSheet sheet = wb.getSheetAt(0);
/* // 创建新的Excel 工作簿
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
// 在索引0的位置创建行(最顶端的行)
XSSFRow row = sheet.createRow((short) 0);
// 在索引0的位置创建单元格(左上端)
XSSFCell cell = row.createCell((short) 0);
// 定义单元格为字符串类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
// 在单元格中输入一些内容
cell.setCellValue("增加值");
*/
// 插入 PNG 图片至 Excel
InputStream is = new FileInputStream("D:\456.jpg");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
// 图片插入坐标
anchor.setCol1(6); //列
anchor.setRow1(0); //行
// 插入图片
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
// 新建一输出文件流
FileOutputStream fOut = new FileOutputStream("D:\test.xlsx");
// 把相应的Excel 工作簿存盘
wb.write(fOut);
fOut.flush();
// 操作结束,关闭文件
fOut.close();
System.out.println("文件生成...");
} catch (Exception e) {
System.out.println("已运行 xlCreate() : " + e);
}