https://bz.apache.org/bugzilla/show_bug.cgi?id=58422
Bug ID: 58422
Summary: How to add image to header of Excel?
Product: POI
Version: 3.9-FINAL
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P2
Component: SXSSF
Assignee: [email protected]
Reporter: [email protected]
Hi,
I want to add a image to Header of excel .As long I can see all the methods of
"org.apache.poi.ss.usermodel.HeaderFooter" class is have string argument .How
can I add image to header portion??
Code:
-------------------------------------------------------------------------------------
public static void main(String[] args) {
try {
HeaderFooter vHead = null;
int idx = 0;
int idy = 0;
Cell vFirstCell = null;
Cell vLastCell = null;
Cell vCell = null;
FileOutputStream fileOut = new FileOutputStream("poi-test.xlsx");
SXSSFWorkbook workbook = new SXSSFWorkbook(100);
SXSSFSheet worksheet = (SXSSFSheet) workbook.createSheet("POI
Worksheet");
vHead = worksheet.getHeader();
InputStream my_banner_image = new
FileInputStream("C:\\Users\\RATI\\Desktop\\rati.jpg");
byte[] bytes = IOUtils.toByteArray(my_banner_image);
int my_picture_id = workbook.addPicture(bytes,
Workbook.PICTURE_TYPE_JPEG);
my_banner_image.close();
CreationHelper helper = workbook.getCreationHelper();
Drawing drawing = worksheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
Picture pict = drawing.createPicture(anchor, my_picture_id);
vHead.setCenter(HSSFHeader.font("Times New Roman", "Bold") +
HSSFHeader.fontSize((short) 12) + "Rati");
vHead.setRight(HSSFHeader.font("Times New Roman", "Bold") +
HSSFHeader.fontSize((short) 8) + "&[Picture]");
// index from 0,0... cell A1 is cell(0,0)
Row row1 = worksheet.createRow(idx++);
vCell = row1.createCell(idy++);
vFirstCell = vCell;
vCell.setCellValue("NAME1");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME2");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME3");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME4");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME5");
idy = 0;
row1 = worksheet.createRow(idx++);
vCell = row1.createCell(idy++);
vFirstCell = vCell;
vCell.setCellValue("NAME1");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME2");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME3");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME4");
vCell = row1.createCell(idy++);
vCell.setCellValue("NAME5");
for (int i = 0; i < 100; i++) {
row1 = worksheet.createRow(idx++);
idy = 0;
for (int j = 0; j < 5; j++) {
vCell = row1.createCell(idy++);
vCell.setCellValue("TEST--" + i + "--DATA--" + j);
vLastCell = vCell;
}
}
for (int i = 0; i < 5; i++) {
// worksheet.autoSizeColumn(i);
}
worksheet.setAutoFilter(new CellRangeAddress(1, 101, 0, 4));
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]