看起来您可能必须NumberFormatId
根据此 SO 答案编写自己的自定义:https ://stackoverflow.com/a/7900397/541208 ,或者,在ClosedXML
文档中,它说要添加一个新的Style
:
var workbook = new XLWorkbook();
var ws = workbook.Worksheets.Add("Style NumberFormat");
var co = 2;
var ro = 1;
// Using a custom format
ws.Cell(++ro, co).Value = "123456.789";
ws.Cell(ro, co).Style.NumberFormat.Format = "$ #,##0.00";
ws.Cell(++ro, co).Value = "12.345";
ws.Cell(ro, co).Style.NumberFormat.Format = "0000";
// Using a OpenXML's predefined formats
ws.Cell(++ro, co).Value = "12.345";
ws.Cell(ro, co).Style.NumberFormat.NumberFormatId = 3;
ws.Column(co).AdjustToContents();
workbook.SaveAs("StylesNumberFormat.xlsx");
因此,您的自定义NumberFormat
将类似于0.0%
基于此处列出的默认格式:
ws.Cell(ro, co).Style.NumberFormat.Format = "0.0%";