python XlsxWriter:设置字体不会影响输出 excel 文件中单元格的外观

python XlsxWriter: set font does not affect the appearance of cells in output excel file

我使用 XlsxWriter python 包从我的数据中生成了一个 excel 文件。我尝试了几种方法将我的字体 'B Nazanin' 应用到单元格:

title_cell_format.set_font_name('B Nazanin')
title_cell_format.set_font_family('B Nazanin')
title_cell_format.set_font('B Nazanin')

当我使用其中一种方法时,我可以看到字体名称,但字体外观与输出 excel 文件中的 "B Nazanin" 不同:

我猜解决方案应该是设置文本方向,可以在以下菜单中的 excel 中手动完成。现在的问题是如何在我的 python 程序中设置这个属性!!

它没有记录,主要是因为没有人要求它,但您可以使用格式 reading_order 属性.

设置单元格文本方向

从右到左是阅读顺序 2:

title_cell_format.set_reading_order(2)

更新:

此问题与 reading_order/text 方向无关。看起来它更可能与该特定字体的字符集有关。以下需要来自 GitHub 的最新 XlsxWriter 代码,但应该可以解决问题:

title_cell_format.set_font('B Nazanin')
title_cell_format.set_font_family(0)
title_cell_format.set_font_charset(178)