Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 包装文本xlsxwriter列pd dataframe python_Python 3.x_Pandas_Conditional Formatting_Xlsxwriter - Fatal编程技术网

Python 3.x 包装文本xlsxwriter列pd dataframe python

Python 3.x 包装文本xlsxwriter列pd dataframe python,python-3.x,pandas,conditional-formatting,xlsxwriter,Python 3.x,Pandas,Conditional Formatting,Xlsxwriter,我有一个xlsx文件,我正试图写入该文件,但由于某些原因,似乎无法对单元格中要包装的文本进行格式化: 我试过像贝娄一样(去掉了我认为不重要的行),但文本不会换行,如果我做了其他条件格式化,它会工作,这个文本不会换行: the df is defined... writer = pd.ExcelWriter(f"{xlsx_file}", engine='xlsxwriter') df['Statistics'].to_excel(writer, sheet_name='S

我有一个xlsx文件,我正试图写入该文件,但由于某些原因,似乎无法对单元格中要包装的文本进行格式化:

我试过像贝娄一样(去掉了我认为不重要的行),但文本不会换行,如果我做了其他条件格式化,它会工作,这个文本不会换行:

the df is defined...

writer = pd.ExcelWriter(f"{xlsx_file}", engine='xlsxwriter')

df['Statistics'].to_excel(writer, sheet_name='Statistics', index=False)
...
text_wrap = workbook.add_format({'text_wrap': True})
...
for sheet in all_sheets:
        worksheet = writer.sheets[f"{sheet}"]
        worksheet.set_column(1, 6, 25)
        if sheet == "Statistics":
            worksheet.conditional_format(f'A1:A16', {'type': 'cell',
                                                     'criteria': '!=',
                                                     'value': '0',
                                                     'format': text_wrap})

writer.save()
为了简单起见,我从上面的代码中删除了工作簿和其他我认为不相关的行。 其思想是,有一个包含多个工作表的工作簿,并且只希望将条件格式应用于特定工作表中的一列(第一列)

谢谢你的帮助

我试过像下面这样(…),但文本不会换行,如果我做其他条件格式化,它会工作,这个文本不会换行


Excel不支持条件格式中的文本换行或其他对齐属性,因此XlsxWriter格式被忽略(Excel)。

Hmm,没有其他方法让它编写为人类可读的格式?这个想法是一些单元格有60个字符。而其他人则寥寥无几,不知道如何让它更具可读性。我想把柱子的宽度做得更大,但像这样,所有的东西都会偏向右边。。