I have a problem with setting a different format in each cell, I want to set the number format to a thousand separators and a thousandth separator with 3 decimal places, when the number is not integer, here is my code, I think the problem looks like every cell format is set to last setup fomat for loop
therefore, the conclusion should be like this: 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; }}}}
source share