使用 python (openpyxl) 从 excel 中删除网格线 [英] Removing gridlines from excel using python (openpyxl)
问题描述
我正在尝试从使用 openpyxl 创建的 excel 工作表中删除网格线,但它不起作用.我正在这样做:
I'm trying to remove gridlines from excel worksheet which I created using openpyxl, and it's not working. I'm doing this:
wb = Workbook()
ws = wb.get_active_sheet()
ws.show_gridlines = False
print ws.show_gridlines
wb.save('file.xlsx')
该代码打印假",但保存的文件显示网格线.
The that code prints the 'False', yet the saved file shows gridlines.
推荐答案
有一个相关的问题.另外,根据源代码 show_gridlines
只是一个完全没有影响的工作表类属性.只需观看问题即可获得任何更新.
There is a relevant issue in openpyxl
issue tracker. Plus, according to the source code show_gridlines
is just a worksheet class property that has no affect at all. Just watch the issue to get any update on it.
作为替代解决方案,请尝试新的、很棒的 xlsxwriter 模块.它能够隐藏工作表上的网格线(请参阅 docs).举个例子:
As an alternative solution, try the new and awesome xlsxwriter module. It has an ability to hide grid lines on a worksheet (see docs). Here's an example:
from xlsxwriter.workbook import Workbook
workbook = Workbook('hello_world.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
worksheet.hide_gridlines(2)
workbook.close()
这篇关于使用 python (openpyxl) 从 excel 中删除网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!