I have a condition where in I need to check for the Delimiter in a string. If found then I need to set excel cell to blank. I have this code:
row = sheet.createRow(newRow);
for(String fieldValues: fieldList)
{
if(fieldValues.contains(","))
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellValue(Cell.CELL_TYPE_BLANK);
cellNo++;
}
else
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellValue(fieldValues);
cellNo++;
}
}
Cell.CELL_TYPE_BLANK is not setting up the Blank Cell even I tried with cell.setCellValue("") but again it doesn't set. Does it try to skip that cell if we want to set a Blank Cell? if not then can anyone let me know how I can do that.
Appreciate your help!!
One way to do what you're requesting is to use HSSFCell. getColumnIndex() . Row. getCell(int) is not deprecated!
To create a cell in Excel Sheet, we can use Apache POI which provides createCell() method. This method requires an integer argument which should be a column number. The createCell() is a method of Row class. Lets see an example in which we are creating a cell at the specified location.
Apache POI provides three methods for changing the background color. In the CellStyle class, we can use the setFillForegroundColor, setFillPattern, and setFillBackgroundColor methods for this purpose. A list of colors is defined in the IndexedColors class. Similarly, a list of patterns is defined in FillPatternType.
According to the Documentation and POI implementation I'd expect that
cell.setCellType(Cell.CELL_TYPE_BLANK);
should do the trick and is all you need.
I am a little late but,
dont think about setting the cell to be empty. Think about leaving the cell empty. When you create a Cell, it is empty by default until you set it's value.
try something like this:
row = sheet.createRow(newRow);
for(String fieldValues: fieldList)
{
if(fieldValues.contains(","))
{
XSSFCell cell = row.createCell(cellNo); //it's already blank here
cellNo++;
}
else
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellValue(fieldValues);
cellNo++;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With