我正在使用 Apache.POI 创建一个 xlsx 并在顶部插入一个徽标,我如何冻结或锁定图像,以便在下载 xlsx 后无法更改它。
int numberOfSheets = wb.getNumberOfSheets();
for(int i=0;i<numberOfSheets;i++)
{
XSSFSheet sheet = wb.getSheetAt(i);
try {
//insert a logo
String location = "C:/Git/cc/src/main/resources/logo/VCC_logo.jpg"; // hard coded for testing
InputStream is = new FileInputStream(location);
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
// Create Winner sheet
CreationHelper creationHelper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor =
creationHelper.createClientAnchor();
anchor.setCol1(0);
anchor.setRow1(0);
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize(2.5,2.5);
pict.getImageDimension().setSize(3.0,3.0);
sheet.createFreezePane(0,3);
} catch (FileNotFoundException e) {
throw new nException("Problem in reading VCC_logo.jpg");
} catch (IOException io) {
throw new Exception("Problem in reading VCC_logo.jpg");
}