You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Syed Hasan <sm...@hotmail.com> on 2012/02/23 16:58:41 UTC
write in a sheet
Hi I'm reading a WorkBook using POi and then highlighting certain cells based on
my calculation.
If my workbook has only one sheet then its work fine; but if there are multiple
sheets then it gets scrued up. I'm doing something as follows:
for( each workBook){
for(each workSheet){
//do some calcualtion on the cells...
highLightCells(workBook, workSheet, cellToHighLight)
}
}
highLightCells(workBook, workSheet, cellToHighLight){
try{
this.outputStream = new FileOutputStream(workbook.getFileName());
String startPosition = maskingInfo.getStartPosition();
ArrayList<Integer> startP = this.convertPosition(startPosition);
String endPosition = maskingInfo.getEndPosition();
ArrayList<Integer> endP = this.convertPosition(endPosition);
// index=1 in both Lists(startP, endP) contain numeric digits of position.
//eg: position = G23; startP.get(1) = 23
//iterate through all rows after the columnHeaderRow
for(int rowNum = startP.get(1); rowNum <= endP.get(1); rowNum++){
HSSFRow row = workSheet.getSheet().getRow(rowNum); // get the current row
if (row == null) { // if any row is EMPTY, poi treats it as null
continue;
}
// get the specific column
HSSFCell cell = row.getCell(startP.get(0));
if (cell == null) {
continue;
}
else{
HSSFCellStyle cellStyle = cell.getCellStyle();
//create and set a new font for this cell
cellStyle.setFont(this.getCamoFont(workbook.getExcelWorkBook()));
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
}
}
// write back to the workBook
workSheet.getSheet().getWorkbook().write(this.outputStream);
outputStream.flush();
outputStream.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
I guess, when POI is writing back to worksheet, I need to some how keep track
whether its finished before it goes to the next sheet. Any comments, how can I
do that?
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: write in a sheet
Posted by shasan <sm...@hotmail.com>.
Modifying current cell's CellStyle effects other cell for no good reason...
After trying and banging my heads for all day,
I found the following comments in http://
http://poi.apache.org/spreadsheet/quick-guide.html http://
http://poi.apache.org/spreadsheet/quick-guide.html
"
It is important to create a new cell style from the workbook otherwise
you can end up
modifying the built in style and effecting not only this cell but other
cells.
"
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/write-in-a-sheet-tp5508529p5509271.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org