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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to