简体   繁体   English

pyexcelerator:如何通过工作表名称删除Excel工作表

[英]pyexcelerator: how to delete a excel-sheet by sheet-name

As titled, I'm using pyexcelerator to operate excel files. 如标题所示,我正在使用pyexcelerator操作excel文件。

Code: 码:

from pyExcelerator import parse_xls
fpath='D:\\Capacity_20120811.xls'
eData=parse_xls(fpath)




>>> eData
[(u'testExcelReport_hr',
  {(0, 0): u'Deletetime',
   (0, 1): u'Food',
   (0, 2): u'Peak Rate',
   (0, 3): u'Total Bytes',
   (0, 4): u'Total Msg No',
   (1, 0): u'20110824T05',
   (1, 1): u'111BSA',
   (1, 2): 6255326.0,
   (1, 3): 16226057.0,
   (1, 4): 127.0,
   (2, 0): u'20110824T06',
   (2, 1): u'111BSA',
   (2, 2): 352978.0,
   (2, 3): 672104.0,
   (2, 4): 2124.0})]

I want delete sheet by sheetname:'testExcelReport_hr' 我想按工作表名称删除工作表sheetname:'testExcelReport_hr'

You could use a list comprehension for that: 您可以为此使用列表理解:

eData = [(sheet_name, sheet_data) for (sheet_name, sheet_data) in eData
         if sheet_name != u'testExcelReport_hr']

This keeps all sheets except for the one named testExcelReport_hr , in effect removing that sheet. 这将保留testExcelReport_hrtestExcelReport_hr之外的所有工作表,实际上是删除了该工作表。

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

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