0

I'm creating an xlsx using Apache.POI and inserting a logo at the top,how do I freeze or lock the images so that it cant be changed once the xlsx is downloaded.

      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");
                }
tyro
  • 765
  • 2
  • 13
  • 34

1 Answers1

0

If your logo starts at row i and column j. You could use the API createFreezePane like :

Sheet.createFreezePane( i, j );

SomeDude
  • 13,876
  • 5
  • 21
  • 44
  • Yes, I tried that but it is freezing the rows and images on that pane is still movable in the sheet. I have 2 sheets on xlsx, when I open the xlsx the images is locked cant move, but as soon as I go to 2nd sheet and try to move the image it starts moving for 1st sheet as well. – tyro Jun 27 '17 at 13:44
  • you have to call createFreezePane on the sheet you want to freeze. Please post the code in the question to get better help. – SomeDude Jun 27 '17 at 14:23
  • Where are you calling createFreezePane ? – SomeDude Jun 28 '17 at 13:05