java - Apache POI not styling entire row -
i'm using apache poi generate reports, , having issues in styling rows. when open generated excel file, styling of row starts after column 25, i've tried , cannot figure out why..
here's code:
import java.io.fileoutputstream; import java.io.ioexception; import java.util.linkedhashmap; import org.apache.poi.encrypteddocumentexception; import org.apache.poi.hssf.usermodel.hssfcellstyle; import org.apache.poi.hssf.usermodel.hssfworkbook; import org.apache.poi.hssf.util.hssfcolor; import org.apache.poi.ss.usermodel.cell; import org.apache.poi.ss.usermodel.cellstyle; import org.apache.poi.ss.usermodel.row; import org.apache.poi.ss.usermodel.sheet; import org.apache.poi.ss.usermodel.workbook; public class printexcel { static void print(linkedhashmap<rowreport,rowreport> map, string filename) { try { workbook wb = new hssfworkbook(); sheet sheet = wb.createsheet("diffreport"); int iterator_row = 0,iterator_cell = 0; cellstyle style = wb.createcellstyle(); style.setfillforegroundcolor(hssfcolor.red.index); style.setfillpattern(hssfcellstyle.solid_foreground); //iterate through rows for(rowreport row : map.keyset()) { row rowdestination = sheet.createrow((short)iterator_row); //celldestination.setcellstyle(style); for(iterator_cell = 0; iterator_cell <= 25; iterator_cell++) { cell celldestination = rowdestination.createcell(iterator_cell); switch (iterator_cell) { case 0: celldestination.setcellvalue(row.getplace()); break; case 1: celldestination.setcellvalue(row.getpoint()); break; case 2: celldestination.setcellvalue(row.getside()); break; case 3: celldestination.setcellvalue(row.getsub_sector()); break; case 4: celldestination.setcellvalue(row.getposition()); break; case 5: celldestination.setcellvalue(row.getbeam()); break; case 6: celldestination.setcellvalue(row.getsector()); break; case 7: celldestination.setcellvalue(row.gettpg300_name()); break; case 8: celldestination.setcellvalue(row.getsecond_name()); break; case 9: celldestination.setcellvalue(row.getprogram()); break; case 10: celldestination.setcellvalue(row.getcard_a_type()); break; case 11: celldestination.setcellvalue(row.getcard_b_type()); break; case 12: celldestination.setcellvalue(row.getunit()); break; case 13: celldestination.setcellvalue(row.getunderange()); break; case 14: celldestination.setcellvalue(row.geta1()); break; case 15: celldestination.setcellvalue(row.geta2()); break; case 16: celldestination.setcellvalue(row.getb1()); break; case 17: celldestination.setcellvalue(row.getb2()); break; case 18: celldestination.setcellvalue(row.getcardinal()); break; case 19: celldestination.setcellvalue(row.getsource()); break; case 20: celldestination.setcellvalue(row.getgauge()); break; case 21: celldestination.setcellvalue(row.getfilter()); break; case 22: celldestination.setcellvalue(row.getvalid()); break; case 23: celldestination.setcellvalue(row.getstatus()); break; case 24: celldestination.setcellvalue(row.getupthreshold()); break; case 25: celldestination.setcellvalue(row.getlowthreshold()); break; default: break; } } rowdestination.setrowstyle(style); iterator_row++; } fileoutputstream fileout = new fileoutputstream(filename); wb.write(fileout); wb.close(); fileout.close(); } catch (encrypteddocumentexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
you need call
rowdestination.setrowstyle(style) in loop terminates @ index <= 25.
you call after loop finishes
Comments
Post a Comment