wie fügen Sie Bilder in HSSFCell in apache POI?

Wie auf Bild hinzufügen in verschiedene HSSFCell Objekt in poi ?

Ich geschrieben habe einigen code hinzufügen Bild, sondern das problem ist, das die Zelle, auf der ich Hinzugefügt letzten Bild, Dass die Zelle nur zeigen, Bild anderes, als dass keine anderen Zellen zeigen Bilder ...

dankbar für Ihre Hilfe ...

Mein Code ist

while(rs.next()){

    HSSFCell cell = getHSSFCell(sheet, rowNo, cellNo);

    cell.setCellValue(new HSSFRichTextString(rs.getString("TEST_STEP_DETAILS")) );
    cell.setCellStyle(style);

    String annotate = rs.getString("ANNOTATE");

    if(annotate != null){                       
        int index = getPicIndex(wb);
        HSSFPatriarch patriarch=sheet.createDrawingPatriarch();
        HSSFClientAnchor anchor = new HSSFClientAnchor(400,10,655,200,(short)cellNo,(rowNo+1),(short)cellNo,(rowNo+1));
        anchor.setAnchorType(1);
        patriarch.createPicture(anchor, index);                                         
    }
    cellNo++;
}

getPicIndex METHODE :-

public static int getPicIndex(HSSFWorkbook wb){
    int index = -1;
    try {
        byte[] picData = null;
        File pic = new File( "C:\\pdf\\logo.jpg" );
        long length = pic.length(  );
        picData = new byte[ ( int ) length ];
        FileInputStream picIn = new FileInputStream( pic );
        picIn.read( picData );
        index = wb.addPicture( picData, HSSFWorkbook.PICTURE_TYPE_JPEG );
    } catch (IOException e) {
        e.printStackTrace();
    }  catch (Exception e) {
        e.printStackTrace();
    } 
    return index;
}
InformationsquelleAutor Garudadwajan | 2009-07-14
Schreibe einen Kommentar