简体   繁体   中英

pyexcelerator: how to delete a excel-sheet by sheet-name

As titled, I'm using pyexcelerator to operate excel files.

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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