简体   繁体   English

使用 xlsxwriter 循环查看索引的工作表

[英]Looping through sheets looking at index using xlsxwriter

I am wondering is their anyway I can iterate over a worksheet and determine len of my index using xlsxwriter?我想知道他们无论如何我可以遍历工作表并使用 xlsxwriter 确定我的索引的 len 吗? The code that I am using right now isnt working how I want.我现在使用的代码无法按我想要的方式工作。

for worksheet in workbook.worksheets():
    if len(worksheet.index) <= 1:
       worksheet.hide()
    else:
        move on and do something else

what I am expecting it to do is look and see if their is more than 1 row of data and if their is continue else hide that worksheet.我期望它做的是查看它们是否超过 1 行数据,如果它们继续,则隐藏该工作表。 once again I am using xlsxwriter and I havent found a way to do that.我再次使用 xlsxwriter,但我还没有找到一种方法来做到这一点。 Any help would be greatly appreciated任何帮助将不胜感激

There is no public method to determine is a XlsxWriter worksheet has data since the parent application can track this itself when it adds data.没有公共方法可以确定 XlsxWriter 工作表是否有数据,因为父应用程序可以在添加数据时自行跟踪。

As an alternative you could check that the worksheet.dim_rowmax is not None .作为替代方案,您可以检查worksheet.dim_rowmax是否不是None

PS it is a little odd that the application is adding empty worksheets and then hiding them. PS,应用程序添加空工作表然后隐藏它们有点奇怪。 This may be confusing to the end user.这可能会使最终用户感到困惑。 Maybe you can figure out if you need to add data first before creating empty worksheets.也许您可以弄清楚是否需要在创建空工作表之前先添加数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM