Embed files into XSSF sheets in Excel, using Apache POI

前端 未结 2 1567
花落未央
花落未央 2020-12-06 14:03

I have found kiwiwings answer to the question of how you can embed files into Excel using Apache POI, but unfortunately his answer only covers HSSF spreadsheets (the XLS for

2条回答
  •  眼角桃花
    2020-12-06 14:50

    I've applied a patch via #60586, so embedding is now much easier. The following snipplet is taken from the corresponding JUnit test.

    Workbook wb1 = new XSSFWorkbook();
    Sheet sh = wb1.createSheet();
    int picIdx = wb1.addPicture(getSamplePng(), Workbook.PICTURE_TYPE_PNG);
    byte samplePPTX[] = getSamplePPT(true);
    int oleIdx = wb1.addOlePackage(samplePPTX, "dummy.pptx", "dummy.pptx", "dummy.pptx");
    
    Drawing pat = sh.createDrawingPatriarch();
    ClientAnchor anchor = pat.createAnchor(0, 0, 0, 0, 1, 1, 3, 6);
    pat.createObjectData(anchor, oleIdx, picIdx);
    

提交回复
热议问题