Im trying to format specific XLS cell to the "percentage" format. I read this post: Format cell as percantage NPOI c# When I use this solution it helps but the problem is that for example: 51.35% keep at excel as 5135.00%.
This is my code:
XSSFCellStyle percentageStyle = (XSSFCellStyle)workbook.CreateCellStyle();
percentageStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
XSSFCell c = (XSSFCell)dataRow.CreateCell(column.Ordinal);
string val = row[column].ToString();
if (!String.IsNullOrEmpty(val) && val.Contains('%'))
{
string val2 = val.Trim('%');
//Console.WriteLine("percent!" + val);
c.SetCellValue(Double.Parse(val2));
c.CellStyle = percentageStyle;
}
Is there any way to change it? I would like that the 'Number' value will be kept with '%'. Images are attached.Format cells number Format cells percentage