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.

Mon Sep 16, 2024 4:27 pm

Hello,
I have a problem when using the python library-3.11.9, spire.xls-14.7.3. I am hosting a linux server bot, however, an error appears when it starts. I use the library to convert a table to a photo. Help please.
code:
Code: Select all
    def create_image_from_excel(number):
    week_number = get_week_number() + number
    img_filename = f"week-{week_number}.jpg"

    if os.path.exists(img_filename):
        return
       
    process_excel_file(number)
    zip_file = 'Fonts.rar'
    with zipfile.ZipFile("Fonts.zip","r") as zip_ref:
        zip_ref.extractall(os.getcwd())
    workbook = Workbook()
    font_dir = os.path.join(os.getcwd(), 'Fonts')
    workbook.CustomFontFileDirectory = font_dir
    workbook.LoadFromFile('dz.xlsx')
    sheet = workbook.Worksheets[f"week-{week_number}"]
    image = sheet.ToImage(1, 1, 10, 9)
    image.Save(img_filename)
    workbook.Dispose()


and error:
Code: Select all
   spire.xls.common.SpireException: Cannot found font installed on the system.:   at sprb2j.spragd(String, sprj, String) + 0xa3
   at sprdi9.spra(String, sprj, String) + 0x2ae
   at sprdxs.spra(String, Double, Double) + 0x206
   at sprdjm.sprz(Int32) + 0x2f
   at spre23.sprb() + 0x10f
   at spre23.spre(sprdlp) + 0xab
   at spre23.sprc(sprdlp) + 0x5c2
   at spre23.spra(Int32) + 0x69
   at spre3h.spra(ConverterSetting, Int32&) + 0x4f6
   at spre3i..ctor(sprdlm, ConverterSetting, sprdln, sprfl1) + 0x10a
   at Spire.Xls.Core.Spreadsheet.XlsWorkbook.spra(Int32, Int32, Int32, Int32, Int32, Single, Single, sprbcb&, Stream&) + 0x8fb
   at Spire.Xls.Core.Spreadsheet.XlsWorkbook.SaveAsImagesInternal(Int32, Int32, Int32, Int32, Int32, Single, Single) + 0x2b
   at Spire.Xls.Core.Spreadsheet.XlsWorksheet.ToImage(Int32, Int32, Int32, Int32) + 0xd0
   at Spire.Xls.AOT.NLXlsWorksheet.XlsWorksheet_ToImage(IntPtr, Int32, Int32, Int32, Int32, IntPtr) + 0x6f

Data and Fonts in GitHub Amir10202010/dz-bot

Best regards,
Amirkhan

Amir1020
 
Posts: 3
Joined: Mon Sep 16, 2024 3:35 pm

Tue Sep 17, 2024 3:20 am

Dear Amirkhan,

Thank you for your inquiry.
Upon reviewing your document, I noticed that the 'DengXian' font is being used, which does not appear to be present in your Font directory. Please upload the attached font to your server and re-validate. If the issue persists, could you provide detailed information about your Linux server, such as CentOS 7.8?

Sincerely,
Nina
E-iceblue support team
Attachments
Deng.zip
(9.59 MiB) Downloaded 165 times
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Tue Sep 17, 2024 2:20 pm

Dear Nina,

Thank you for your prompt response. Unfortunately, the suggested solution did not resolve the issue, and I am still encountering the same error. The hosting site is Render, and it uses an Ubuntu Linux server rather than CentOS 7.8.

Could you please provide further guidance or an alternative solution?

Sincerely,
Amirkhan


code
Code: Select all
def create_image_from_excel(number):
    week_number = get_week_number() + number
    img_filename = f"week-{week_number}.jpg"

    if os.path.exists(img_filename):
        return
       
    process_excel_file(number)
   
    workbook = Workbook()
    font_dir = os.path.join(os.getcwd(), 'Fonts')
    workbook.CustomFontFileDirectory = font_dir
    workbook.LoadFromFile('dz.xlsx')
    sheet = workbook.Worksheets[f"week-{week_number}"]
    image = sheet.ToImage(1, 1, 10, 9)
    image.Save(img_filename)
    workbook.Dispose()


issue
Code: Select all
main.create_image_from_excel(users[callback.from_user.id]['week'])
  File "/opt/render/project/src/main.py", line 117, in create_image_from_excel
    image = sheet.ToImage(1, 1, 10, 9)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/render/project/src/.venv/lib/python3.11/site-packages/spire/xls/XlsWorksheet.py", line 934, in ToImage
    intPtr = CallCFunction(GetDllLibXls().XlsWorksheet_ToImage, self.Ptr, firstRow,firstColumn,lastRow,lastColumn)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/render/project/src/.venv/lib/python3.11/site-packages/spire/xls/common/__init__.py", line 109, in CallCFunction
    raise SpireException(info)
spire.xls.common.SpireException: Cannot found font installed on the system.:   at sprb2j.spragd(String, sprj, String) + 0xa3
   at sprdi9.spra(String, sprj, String) + 0x2ae
   at sprdxs.spra(String, Double, Double) + 0x206
   at sprdjm.sprz(Int32) + 0x2f
   at spre23.sprb() + 0x10f
   at spre23.spre(sprdlp) + 0xab
   at spre23.sprc(sprdlp) + 0x5c2
   at spre23.spra(Int32) + 0x69
   at spre3h.spra(ConverterSetting, Int32&) + 0x4f6
   at spre3i..ctor(sprdlm, ConverterSetting, sprdln, sprfl1) + 0x10a
   at Spire.Xls.Core.Spreadsheet.XlsWorkbook.spra(Int32, Int32, Int32, Int32, Int32, Single, Single, sprbcb&, Stream&) + 0x8fb
   at Spire.Xls.Core.Spreadsheet.XlsWorkbook.SaveAsImagesInternal(Int32, Int32, Int32, Int32, Int32, Single, Single) + 0x2b
   at Spire.Xls.Core.Spreadsheet.XlsWorksheet.ToImage(Int32, Int32, Int32, Int32) + 0xd0
   at Spire.Xls.AOT.NLXlsWorksheet.XlsWorksheet_ToImage(IntPtr, Int32, Int32, Int32, Int32, IntPtr) + 0x6f

Amir1020
 
Posts: 3
Joined: Mon Sep 16, 2024 3:35 pm

Wed Sep 18, 2024 10:05 am

Hi,

Thanks for your feedback.
The CustomFontFileDirectory should receive a list, please correct as below to try again.
Code: Select all
workbook.CustomFontFileDirectory = [(font_dir)]

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Wed Sep 18, 2024 2:06 pm

Hi Nina,

Thank you for your suggestion. Your method worked perfectly! I changed the folder from C:/windows/fonts to appdata/local/microsoft/fontcache/cloud-fonts, and the issue was resolved.

I appreciate your help!

Sincerely,
Amirkhan

Amir1020
 
Posts: 3
Joined: Mon Sep 16, 2024 3:35 pm

Thu Sep 19, 2024 5:38 am

Dear Amirkhan,

Thanks for your confirmation.
If you need assistance in the future, please feel free to write back.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS