【发布时间】:2017-07-26 14:35:46
【问题描述】:
我正在创建一个 excel,当我写一些值示例 1-19 时,当我打开 excel 文档时,我看到 1-19,但如果我点击它,那么 excel 会尝试将其格式化为日期
有没有办法强制工作表不使用任何公式或格式? 我查过了,数据格式是字符串。
private void Test1(ref ISheet worksheet, string[] array, IWorkbook workbook, int iRow, XSSFFont font2)
{
var format = HSSFDataFormat.GetBuiltinFormats();
ICellStyle _TextCellStyle = workbook.CreateCellStyle();
_TextCellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("@");
IRow file = worksheet.CreateRow(iRow);
int iCol = 0;
for (int y = 0; y < array.Length; y++)
{
ICellStyle style = workbook.CreateCellStyle();
style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
//style.DataFormat = HSSFDataFormat.
ICell cell = file.CreateCell(iCol, CellType.String);
cell.SetCellValue(array[y]);
style.SetFont(font2);
// cell.CellStyle = style;
var getst = cell.CellType;
cell.CellStyle = _TextCellStyle;
iCol++;
getst = cell.CellType;
}
}
【问题讨论】:
-
我不认为这是格式问题。它是 Excel 进行自动错误检查。它认为单元格包含日期!你最好把 ' 放在你的 1-19....