Excel 数字格式
使用 FormatString property 来控制在任何 Excel Cell 或 Range 中使用 IronXL for Python 时数值显示的方式。
使用 worksheet["A2"] 可为指定地址选择 Range。 若需访问单个 Cell,可使用 First() method。 不过,FormatString property 既可直接应用于 Cell,也可直接应用于 Range,因此 First() 通常可以省略。 可以使用相同的方法应用其他数字格式,如下面的代码示例所示。
如何在Python中使用Excel数字格式
- 安装IronXL for Python以应用数字格式
- 使用
Loadmethod加载现有Excel文件 - 设置单元格的
FormatStringproperty来指定所需的数字格式 - 使用
SaveAsmethod保存修改后的电子表格
在代码示例中,WorkBook.Load method 用于打开现有的 Excel 文件。 worksheet["A2"] syntax 用于选择特定单元格,而 FormatString property 被设置为 "0.00" 以显示保留两位小数的数值。 最后,SaveAs method 将修改后的工作簿保存为新文件。






