如何用手机做音乐网站,中国建设银行网站签名通下载安装,邢台市,监理建设协会网站我正在为xlutils、xlrd和xlwt创建一个名为excel functions的类#xff0c;最终我可能会创建一个库。如果你有兴趣帮我做一个删除工作表的功能。您可能希望转向openpyxl和/或pyexcel#xff0c;因为它们更容易实现#xff0c;并且有相应的功能。如果要从一个excel工作簿提取数…我正在为xlutils、xlrd和xlwt创建一个名为excel functions的类最终我可能会创建一个库。如果你有兴趣帮我做一个删除工作表的功能。您可能希望转向openpyxl和/或pyexcel因为它们更容易实现并且有相应的功能。如果要从一个excel工作簿提取数据并输出到另一个excel工作簿则需要使用createCopy(原始工作簿、其他工作簿、原始文件名、新文件名)import xlwtimport xlrdimport xlutils.copyimport xlutils class excelFunctions():def getSheetNumber(self, fileName, sheetName):# opens existing workbookworkbook xlrd.open_workbook(fileName, on_demandTrue)#turns sheet name into sheet numberfor index, sheet in enumerate(workbook.sheet_names()):if sheet sheetName:return indexdef createSheet(self, fileName, sheetName):# open existing workbookrb xlrd.open_workbook(fileName, formatting_infoTrue, on_demandTrue)# make a copy of itwb xl_copy(rb)# creates a variable called sheets which stores all the sheet namessheets rb.sheet_names()# creates a string which is equal to the sheetName user inputstr1 sheetName# checks to see if the given sheetName is a current sheetif (str1 not in sheets):# add sheet to workbook with existing sheetsSheet wb.add_sheet(sheetName)# save the sheet with the same file name as beforewb.save(fileName)else:# this declares the sheet variable to be equal to the sheet name the user givessheet wb.get_sheet(self.getSheetNumber(fileName, sheetName))# save the sheet with the same file name as beforewb.save(fileName)def createCopy(self, fileName, fileName2, sheetName, sheetName2):# open existing workbookrb xlrd.open_workbook(fileName, formatting_infoTrue)# defines sheet as the name of the sheet givensheet rb.sheet_by_name(sheetName)# makes a copy of the original sheetwb xl_copy(rb)# creates an int called column_count which is equal to the sheets maximum columnscolumn_count sheet.ncols - 1# creates a blank array called stuffStuff []# this loops through adding columns from the given sheet namefor i in range (0, column_count):Stuff.append([sheet.cell_value(row, i) for row in range(sheet.nrows)])# create a sheet if there is not already a sheetself.createSheet(fileName, sheetName2)# defines sheet as the new sheetsheet wb.get_sheet(self.getSheetNumber(fileName, sheetName2))# this writes to the sheetfor colidx, col in enumerate(Stuff):for rowidx, row in enumerate(col):sheet.write(rowidx, colidx, row)# this saves the filewb.save(fileName2)