[GH-ISSUE #468] format_set_font_name does not work for Persian font. #365

Closed
opened 2026-05-05 12:12:20 -06:00 by gitea-mirror · 14 comments
Owner

Originally created by @mehranj73 on GitHub (Feb 4, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/468

Originally assigned to: @jmcnamara on GitHub.

My problem also happend in Rust lang and setting font_charset to 178 and font_family to 0 fix my problem. I don't know how to do the same thing in your library. I'm using "B Nazanin" and "B titr" fonts.
https://github.com/jmcnamara/rust_xlsxwriter/issues/125

Originally created by @mehranj73 on GitHub (Feb 4, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/468 Originally assigned to: @jmcnamara on GitHub. My problem also happend in Rust lang and setting font_charset to 178 and font_family to 0 fix my problem. I don't know how to do the same thing in your library. I'm using "B Nazanin" and "B titr" fonts. https://github.com/jmcnamara/rust_xlsxwriter/issues/125
gitea-mirror 2026-05-05 12:12:20 -06:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jmcnamara commented on GitHub (Feb 4, 2025):

The APIs you need are

void format_set_font_family(lxw_format *format, uint8_t value);
void format_set_font_charset(lxw_format *format, uint8_t value);

They are public, just not documented because they are rarely required.

<!-- gh-comment-id:2634627147 --> @jmcnamara commented on GitHub (Feb 4, 2025): The APIs you need are ```C void format_set_font_family(lxw_format *format, uint8_t value); void format_set_font_charset(lxw_format *format, uint8_t value); ``` They are public, just not documented because they are rarely required.
Author
Owner

@mehranj73 commented on GitHub (Feb 4, 2025):

Thanks for replying. I actually tried these two methods and didn't work. I also open the excel file as a zip file and didn't see the changes to charset and font family.

<!-- gh-comment-id:2634695078 --> @mehranj73 commented on GitHub (Feb 4, 2025): Thanks for replying. I actually tried these two methods and didn't work. I also open the excel file as a zip file and didn't see the changes to charset and font family.
Author
Owner

@jmcnamara commented on GitHub (Feb 4, 2025):

My bad. I hadn't added the code to use font_charset. I've pushed it to main so you can try it.

Here is an example:

#include "xlsxwriter.h"

int main()
{

    lxw_workbook *workbook = workbook_new("gh468.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Set the cell size for clarity. */
    worksheet_set_column(worksheet, 0, 0, 60, NULL);
    worksheet_set_row(worksheet, 0, 100, NULL);

    /* Add a format with a font that supports Persian. */
    lxw_format *format = workbook_add_format(workbook);

    format_set_font_name(format, "B Titr");
    format_set_font_size(format, 72);
    format_set_font_charset(format, 178);
    format_set_font_family(format, 0);
    format_set_bold(format);
    format_set_align(format, LXW_ALIGN_CENTER);
    format_set_align(format, LXW_ALIGN_VERTICAL_CENTER);

    /* Write a test string. */
    worksheet_write_string(worksheet, 0, 0, "سلام 100000", format);

    workbook_close(workbook);

    return 0;
}

Output:

Image

Does that look correct?

<!-- gh-comment-id:2634889764 --> @jmcnamara commented on GitHub (Feb 4, 2025): My bad. I hadn't added the code to use `font_charset`. I've pushed it to main so you can try it. Here is an example: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("gh468.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); /* Set the cell size for clarity. */ worksheet_set_column(worksheet, 0, 0, 60, NULL); worksheet_set_row(worksheet, 0, 100, NULL); /* Add a format with a font that supports Persian. */ lxw_format *format = workbook_add_format(workbook); format_set_font_name(format, "B Titr"); format_set_font_size(format, 72); format_set_font_charset(format, 178); format_set_font_family(format, 0); format_set_bold(format); format_set_align(format, LXW_ALIGN_CENTER); format_set_align(format, LXW_ALIGN_VERTICAL_CENTER); /* Write a test string. */ worksheet_write_string(worksheet, 0, 0, "سلام 100000", format); workbook_close(workbook); return 0; } ``` Output: ![Image](https://github.com/user-attachments/assets/4b2e06f5-7e87-408e-9f52-2feb364947ac) Does that look correct?
Author
Owner

@mehranj73 commented on GitHub (Feb 4, 2025):

I'm a newbie. Would it work if I download the library using vcpkg ?

<!-- gh-comment-id:2634900403 --> @mehranj73 commented on GitHub (Feb 4, 2025): I'm a newbie. Would it work if I download the library using vcpkg ?
Author
Owner

@jmcnamara commented on GitHub (Feb 4, 2025):

I can wrap it up into a vcpkg but it will take a few days.

<!-- gh-comment-id:2635177042 --> @jmcnamara commented on GitHub (Feb 4, 2025): I can wrap it up into a vcpkg but it will take a few days.
Author
Owner

@mehranj73 commented on GitHub (Feb 9, 2025):

Is version 1.1.9 has the new changes in vcpkg?

<!-- gh-comment-id:2646616181 --> @mehranj73 commented on GitHub (Feb 9, 2025): Is version 1.1.9 has the new changes in vcpkg?
Author
Owner

@jmcnamara commented on GitHub (Feb 9, 2025):

No. Not yet.

<!-- gh-comment-id:2646635335 --> @jmcnamara commented on GitHub (Feb 9, 2025): No. Not yet.
Author
Owner

@mehranj73 commented on GitHub (Feb 10, 2025):

I have been trying "Using CMake for Microsoft Visual Studio" in this tutorial for a week and I always get "No package 'zlib' found" error.

<!-- gh-comment-id:2648848140 --> @mehranj73 commented on GitHub (Feb 10, 2025): I have been trying "**Using CMake for Microsoft Visual Studio**" in this [tutorial](https://libxlsxwriter.github.io/getting_started.html) for a week and I always get "`No package 'zlib' found`" error.
Author
Owner

@jmcnamara commented on GitHub (Feb 11, 2025):

I have submitted a request to include the updated version, v1.2.0, in vcpkg: https://github.com/microsoft/vcpkg/pull/43758

<!-- gh-comment-id:2649589089 --> @jmcnamara commented on GitHub (Feb 11, 2025): I have submitted a request to include the updated version, v1.2.0, in vcpkg: https://github.com/microsoft/vcpkg/pull/43758
Author
Owner

@jmcnamara commented on GitHub (Feb 11, 2025):

These changes are now upstream in vcpkg libxlsxwriter package version 1.2.0.

Could you test that and let me know if is fixed. Thanks.

<!-- gh-comment-id:2650209247 --> @jmcnamara commented on GitHub (Feb 11, 2025): These changes are now upstream in vcpkg libxlsxwriter package version 1.2.0. Could you test that and let me know if is fixed. Thanks.
Author
Owner

@mehranj73 commented on GitHub (Feb 11, 2025):

The last version still is 1.1.9 in vcpkg.

<!-- gh-comment-id:2651104781 --> @mehranj73 commented on GitHub (Feb 11, 2025): The last version still is 1.1.9 in [vcpkg]( https://vcpkg.io/en/package/libxlsxwriter).
Author
Owner

@jmcnamara commented on GitHub (Feb 11, 2025):

I don't know how long it takes to become available. The upgrade patch was merged upstream yesterday.

<!-- gh-comment-id:2651227629 --> @jmcnamara commented on GitHub (Feb 11, 2025): I don't know how long it takes to become available. The upgrade patch was merged upstream yesterday.
Author
Owner

@jmcnamara commented on GitHub (Feb 13, 2025):

The last version still is 1.1.9 in vcpkg.

I don't know when/how that gets updated but if you clone and run vcpkg from GitHub you can install v1.2.0.

<!-- gh-comment-id:2655166554 --> @jmcnamara commented on GitHub (Feb 13, 2025): > The last version still is 1.1.9 in [vcpkg](https://vcpkg.io/en/package/libxlsxwriter). I don't know when/how that gets updated but if you clone and run vcpkg from GitHub you can install v1.2.0.
Author
Owner

@mehranj73 commented on GitHub (Feb 13, 2025):

Works fine. I tested it with two different fonts. C++ is really hard. I love how Rust's, Python's and Java's package managers are simpler. Thanks, You can close the issue if you want.

<!-- gh-comment-id:2656940006 --> @mehranj73 commented on GitHub (Feb 13, 2025): Works fine. I tested it with two different fonts. C++ is really hard. I love how Rust's, Python's and Java's package managers are simpler. Thanks, You can close the issue if you want.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#365
No description provided.