【问题标题】:How to replace blank cell values with a word in excel Java POI如何在excel Java POI中用单词替换空白单元格值
【发布时间】:2017-04-28 16:53:12
【问题描述】:

如何使用 Java Apache POI 用“不可用”一词填充 Excel 文件中的所有空白单元格?

我使用了以下代码,但它仅适用于某些列我不知道是什么原因?确切地说,它从第 1000 行开始起作用。 (我有一个非常大的 excel 文档)

XSSFRow r1;
for(Row r : firstSheet) 
{
  r1=(XSSFRow) r;                    
  for (Cell cell : r) {                           
   if(cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK)
  {
XSSFCell cell2 = r1.createCell(cell.getColumnIndex());
cell.setCellValue("Not Available");
   }                          
  }
  }

【问题讨论】:

标签: java apache-poi


【解决方案1】:

没有您的代码,很难弄清楚。示例代码

CellReference cr = new CellReference(entry.getKey());
int r = cr.getRow();
int c = cr.getCol();

Row row = sheet.getRow(r);
if (row == null)
    row = sheet.createRow(r);
Cell cell = row.getCell(c, Row.CREATE_NULL_AS_BLANK);
cell.setCellValue("Not Available");

【讨论】:

猜你喜欢
  • 2011-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-04
  • 2022-11-13
  • 1970-01-01
相关资源
最近更新 更多