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:
我有一个条件,我需要检查字符串中的分隔符。如果找到,那么我需要将excel单元格设置为空白。我有这个代码:
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.
即使我尝试使用cell.setCellValue(“”),Cell.CELL_TYPE_BLANK也没有设置空白单元格,但是它再次没有设置。如果我们想要设置空白单元格,它是否会尝试跳过该单元格?如果没有,那么任何人都可以告诉我如何做到这一点。
Appreciate your help!!
感谢你的帮助!!
2 个解决方案
#1
6
According to the Documentation and POI implementation I'd expect that
根据我希望的文档和POI实现
cell.setCellType(Cell.CELL_TYPE_BLANK);
should do the trick and is all you need.
应该做的就是你所需要的。
#2
0
You are using setCellValue
. Instead use this method : setCellStyle
您正在使用setCellValue。而是使用此方法:setCellStyle
row = sheet.createRow(newRow);
for(String fieldValues: fieldList)
{
if(fieldValues.contains(","))
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellStyle(Cell.CELL_TYPE_BLANK);
cellNo++;
}
else
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellValue(fieldValues);
cellNo++;
}
}
#1
6
According to the Documentation and POI implementation I'd expect that
根据我希望的文档和POI实现
cell.setCellType(Cell.CELL_TYPE_BLANK);
should do the trick and is all you need.
应该做的就是你所需要的。
#2
0
You are using setCellValue
. Instead use this method : setCellStyle
您正在使用setCellValue。而是使用此方法:setCellStyle
row = sheet.createRow(newRow);
for(String fieldValues: fieldList)
{
if(fieldValues.contains(","))
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellStyle(Cell.CELL_TYPE_BLANK);
cellNo++;
}
else
{
XSSFCell cell = row.createCell(cellNo);
cell.setCellValue(fieldValues);
cellNo++;
}
}