- Code: Select all
Traceback (most recent call last):
│ File "/home/eric/documents/spirexls-bold-error-mre/./generate_bold_excel.py", line 45, in <module>
│ main()
│ File "/home/eric/documents/spirexls-bold-error-mre/./generate_bold_excel.py", line 29, in main
│ sheet.Range[pos].Style.Font.IsItalic = True
│ File "/home/eric/documents/spirexls-bold-error-mre/venv/lib/python3.9/site-packages/spire/xls/ExcelFont.py", line 28, in IsItalic
│ CallCFunction(GetDllLibXls().ExcelFont_set_IsItalic, self.Ptr, value)
│ File "/home/eric/documents/spirexls-bold-error-mre/venv/lib/python3.9/site-packages/spire/xls/common/__init__.py", line 105, in CallCFunction
│ result = func(*args, **kwargs)
│RuntimeError: ffi_prep_cif_var failed
The code which generated the above is as follows:
- Code: Select all
#!/usr/bin/env python3
""" Source: existing code, tutorial at https://www.e-iceblue.com/Tutorials/Python/Spire.XLS-for-Python/Program-Guide/Data/Python-Set-or-Change-Fonts-in-Excel.html
"""
from spire.xls import *
from spire.xls.common import *
file_path = "bolded.xlsx"
def main() -> None:
wb = Workbook()
wb.Worksheets.Clear()
sheet = wb.Worksheets.Add("Test Sheet")
# fails in a loop
for pos in [(1, 1), (1, 5)]:
sheet.Range[pos].Value = "Test Text"
# Method 1
# sheet.Range[pos].Style.Font.IsBold = True
# Method 2
# fontStyle = wb.Styles.Add('headerFontStyle')
# fontStyle.Font.IsBold = True
# flag = CellStyleFlag()
# flag.FontBold = True
# sheet.Range[pos].ApplyStyle(fontStyle, flag)
# Also fails on italic - Method 1
sheet.Range[pos].Style.Font.IsItalic = True
# Also fails on italic - Method 2
fontStyle = wb.Styles.Add('headerFontStyle')
fontStyle.Font.IsItalic = True
flag = CellStyleFlag()
flag.FontItalic = True
sheet.Range[pos].ApplyStyle(fontStyle, flag)
# also fails when using an explicit range
# sheet.Range[1, 1].Style.Font.IsBold = True
wb.SaveToFile(path, FileFormat.Version2016)
print(f"Done save to {file_path}")
if __name__ == "__main__":
main()
This was run on Ubuntu 22.04.1 LTS with Python 3.9.16 and Spire.Xls version 14.7.3. Any ideas on how to fix this or any workarounds would be greatly appreciated!