我们将在具有货币类型的 Excel 单元格中显示带有货币符号(“TRL”)的数据,我们使用此数据“TRL 100.00”编写 Excel 单元格,然后该单元格自动转换为通用类型而不是货币类型,尽管我们已经更改了使用特定单元格的格式(styleFlag 的属性 NumberFormat=true)
请参阅以下示例代码、其注释和显示输出 Excel 文件的屏幕截图。该代码首先使用TRL 货币格式对单元格 A1进行格式化。然后它用TRL 货币格式格式化整个 C 列。
C#
//Create workbook
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Add some value in cell A1
Cell cell = ws.Cells["A1"];
cell.PutValue(22);
//Format cell A1 with TRL formatting
Style st = cell.GetStyle();
st.Custom = "[$TRL]\\ #,##0.00";
cell.SetStyle(st);
//Make the entire column C with TRL formatting
StyleFlag flg = new StyleFlag();
flg.NumberFormat = true;
ws.Cells.Columns[2].ApplyStyle(st, flg);
//Now enter data in column C cells
ws.Cells["C5"].PutValue(31);
ws.Cells["C6"].PutValue(32);
ws.Cells["C7"].PutValue(33);
ws.Cells["C8"].PutValue(34);
//Save the workbook
wb.Save("output.xlsx");
更新 - 我
显示以下行结果的屏幕截图。
st.Custom = "[$฿-41E]#,##0.00";
注意:我在 Aspose 担任开发布道师
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句