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 將修改過的工作簿儲存為新檔案。






