我在每个单元格中设置不同的格式时遇到问题,我想将数字格式设置为千位分隔符和带有 3 位小数的千位分隔符,当数字不是整数时,这是我的代码,我认为问题看起来像每个单元格格式都是由最后一个格式设置的设置循环
所以输出应该是这样的 12345 -> 12 345; 425 -> 425;41,2 -> 41,2; 4578,25 -> 4 578,25
short doubleFormat = hssfOutputWorkBook.CreateDataFormat().GetFormat("#,##0.###");
short intFormat = hssfOutputWorkBook.CreateDataFormat().GetFormat("#,##0");
for (i = 0; i <= unorderedSheet.LastRowNum; i++)
{
NPOI.SS.UserModel.IRow newRow = orderedSheet.CreateRow(i);
NPOI.SS.UserModel.IRow oldRow = unorderedSheet.GetRow(i);
if (oldRow != null)
{
foreach (ICell oldCell in oldRow.Cells)
{
ICell newCell = newRow.CreateCell(mapping[n]);
switch (oldCell.CellType)
{
case CellType.NUMERIC:
newCell.SetCellType(CellType.NUMERIC);
newCell.SetCellValue(oldCell.NumericCellValue);
if (numberHasDecimals(oldCell.NumericCellValue))
{
newCell.CellStyle.DataFormat = doubleFormat;
}
else
{
newCell.CellStyle.DataFormat = intFormat;
}
break;
default:
newCell.SetCellValue(oldCell.ToString());
break;
}}}}