如何在Xlsxwriter中锁定滚动?

问题描述 投票:1回答:1

我希望停止excel滚过某一行/列。我有一张桌子,我正在使用excel,桌子范围之外的任何地方都需要有无衬里的背景。但是,通过放置无衬里背景,这包括滚动条中的无衬里部分。因此,我想阻止滚动超出表的限制。

我已经尝试过冻结窗格,但是表格扩展超出了屏幕范围(大约50行和列),冻结窗格将不允许滚动整个表格。

python xlsxwriter
1个回答
1
投票

这取决于你在Excel中如何做到这一点。

一种方法是隐藏所有未使用的行和列。为了隐藏大量行,您需要使用Excel优化来隐藏行而不设置每行(大约100万行)。要在XlsxWriter中执行此操作,您可以使用set_default_row()方法。

列不需要此优化,可以使用set_column()隐藏。

这是一个例子:

import xlsxwriter

workbook = xlsxwriter.Workbook('hide_row_col.xlsx')
worksheet = workbook.add_worksheet()

# Write some data.
worksheet.write('D1', 'Some hidden columns.')
worksheet.write('A8', 'Some hidden rows.')

# Hide all rows without data.
worksheet.set_default_row(hide_unused_rows=True)

# Set the height of empty rows that we do want to display even
# if it is the default height.
for row in range(1, 7):
    worksheet.set_row(row, 15)

# Columns can be hidden explicitly. This doesn't increase the file size.
worksheet.set_column('G:XFD', None, None, {'hidden': True})

workbook.close()

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.