Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Oct 16, 2024 9:33 pm

When styling cells (making them bold or italic), I get the following error:

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!

ericcampbell
 
Posts: 8
Joined: Thu Jun 27, 2024 10:39 pm

Thu Oct 17, 2024 5:41 am

Hello,

Thanks for your feedback. I tested and reproduced your issue on Ubuntu 22. This issue has been logged in our bug tracking system under the number SPIREXLS-5475. Our Dev team will investigate it further, once there is any update, we will let you know. We apologize for any inconvenience caused to you.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.XLS