Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Excel reports by programming from templates

I'm using "Apache POI" to generate Excel report. I've a well designed Excel template. I want to create a report by filling the data into predefined locations of the template. That is to say, I do not want to care about the formats of the report. Is that possible? Could you give me some instructions?

like image 872
Sefler Avatar asked Jan 22 '23 11:01

Sefler


2 Answers

I got my answer. I can use the "Cell Naming" utility in Microsoft Excel and then use the following code to locate the cell and do something.

    CellReference[] crefs = this.getCellsByName(wb, cName);

    // Locate the cell position
    Sheet sheet = wb.getSheet(crefs[0].getSheetName());
    Row row = sheet.getRow(crefs[0].getRow());
    Cell cell = row.getCell(crefs[0].getCol());

    // Write in data
    cell.setCellValue(cellRegion.getContent());

"cName" is the cell's name predefined in Microsoft Excel.

like image 54
Sefler Avatar answered Jan 29 '23 11:01

Sefler


You can have a look at jXLS, I think that's what you are looking for.

It takes a Excel as template and you can write a Java app to fill the data:

http://jxls.sourceforge.net/

like image 38
wyz Avatar answered Jan 29 '23 11:01

wyz