I am using apache poi api to generate Excel sheet in my application in java. Data that are set in excel are coming dynamically with type string. For column1, values are alphanumeric. When I generate Excel, it will give me green indication with warning "Number Stored as Text" or "Text date with 2-digit year" on cell.
I want to remove that warning.
I found that from excel we can flag a cell as 'ignore error', to ignore the warning.
How to do it programmatically or is there any other alternative to achieve this task ?
I also have attached screenshot that shows warning with green mark.
Code :
if (cellValue != null && (shouldBeRightAlign))
{
cellType = Cell.CELL_TYPE_NUMERIC;
}
else if (cellValue != null)
{
cellType = Cell.CELL_TYPE_STRING;
}
cell.setCellValue(cellValue);
解决方案
Set the cell type like :
HSSFRow row = sheet.createRow(sheet.getLastRowNum());
HSSFCell cell = row.createCell(0);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
For alphanumeric and Character cell type will be Cell.CELL_TYPE_STRING for number, cell type will be CELL_TYPE_NUMERIC
You can get more on cell type from Cell and HSSFCell documentation.