更改使用XlsxWriter模块创建的XLSX文件中的格式。

huangapple go评论73阅读模式
英文:

Changing Format in XLSX file created using XlsxWriter module

问题

I understand you want the code part to be translated. Here's the translated code:

# 测试表格

# 格式
_format = workbook.add_format({'top': True, 'bottom': True, 'right': True, 'left': True})

_era.to_excel(writer, sheet_name='Test', header=False, index=False, startcol=2, startrow=2)

workbook = writer.book
worksheet = writer.sheets['Test']
worksheet.hide_gridlines(2)
worksheet.conditional_format(2, 2, 20, 11, {'type': 'no_blanks', 'format': _format})

If you have any more code to translate or need further assistance, please let me know.

英文:

I'm trying to change the format in an excel file that has been created using the XlsxWriter module in Python, but so far I haven´t been able to do it. Whenever I open the file in Excel and try to change the border formats nothing happens.

The code I´m using is doing what it is supposed to:

#Test Sheet
    
    #Format
    _format = workbook.add_format({'top':True, 'bottom': True, 'right': True, 'left': True})
    
    _era.to_excel(writer, sheet_name='Test', header=False, index=False, startcol = 2, startrow = 2)
    
    workbook = writer.book
    worksheet = writer.sheets['Test']
    worksheet.hide_gridlines(2)
    worksheet.conditional_format(2, 2, 20, 11, {'type': 'no_blanks', 'format': _format})

The Output:

更改使用XlsxWriter模块创建的XLSX文件中的格式。

But afterwards, when I try to change the cell borders format in Excel, nothing happens, it stays the same:

更改使用XlsxWriter模块创建的XLSX文件中的格式。

更改使用XlsxWriter模块创建的XLSX文件中的格式。

And the result is the exact same thing I downloaded in the first place:
更改使用XlsxWriter模块创建的XLSX文件中的格式。

I've tried lots of things, but I must be missing something regarding the code I´m using, is there somebody willing to help?

Cheers.

答案1

得分: 2

这是发生的原因是因为数据网格正在使用条件格式进行格式化,这会覆盖后来应用于单元格的任何手动边框格式。

这与XlsxWriter无关。在Excel中创建的文件也会出现这种情况。

英文:

The reason this is happening is because the data grid is being formatted with a conditional format and that overrides any manual border format that is later applied to the cells.

This isn't related to XlsxWriter. It would also happen with a file created in Excel.

huangapple
  • 本文由 发表于 2023年7月4日 21:03:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76612947.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定