日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python获取excel数据进行判断输出结果到excel,如何使用python xlrd/xlwt从一个excel工作簿提取数据并输出到另一个excel工作簿?...

發布時間:2024/9/27 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python获取excel数据进行判断输出结果到excel,如何使用python xlrd/xlwt从一个excel工作簿提取数据并输出到另一个excel工作簿?... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我正在為xlutils、xlrd和xlwt創建一個名為excel functions的類,最終我可能會創建一個庫。如果你有興趣幫我做一個刪除工作表的功能。

您可能希望轉向openpyxl和/或pyexcel,因為它們更容易實現,并且有相應的功能。

如果要從一個excel工作簿提取數據并輸出到另一個excel工作簿,則需要使用createCopy(原始工作簿、其他工作簿、原始文件名、新文件名)import xlwt

import xlrd

import xlutils.copy

import xlutils class excelFunctions():

def getSheetNumber(self, fileName, sheetName):

# opens existing workbook

workbook = xlrd.open_workbook(fileName, on_demand=True)

#turns sheet name into sheet number

for index, sheet in enumerate(workbook.sheet_names()):

if sheet == sheetName:

return index

def createSheet(self, fileName, sheetName):

# open existing workbook

rb = xlrd.open_workbook(fileName, formatting_info=True, on_demand=True)

# make a copy of it

wb = xl_copy(rb)

# creates a variable called sheets which stores all the sheet names

sheets = rb.sheet_names()

# creates a string which is equal to the sheetName user input

str1 = sheetName

# checks to see if the given sheetName is a current sheet

if (str1 not in sheets):

# add sheet to workbook with existing sheets

Sheet = wb.add_sheet(sheetName)

# save the sheet with the same file name as before

wb.save(fileName)

else:

# this declares the sheet variable to be equal to the sheet name the user gives

sheet = wb.get_sheet(self.getSheetNumber(fileName, sheetName))

# save the sheet with the same file name as before

wb.save(fileName)

def createCopy(self, fileName, fileName2, sheetName, sheetName2):

# open existing workbook

rb = xlrd.open_workbook(fileName, formatting_info=True)

# defines sheet as the name of the sheet given

sheet = rb.sheet_by_name(sheetName)

# makes a copy of the original sheet

wb = xl_copy(rb)

# creates an int called column_count which is equal to the sheets maximum columns

column_count = sheet.ncols - 1

# creates a blank array called stuff

Stuff = []

# this loops through adding columns from the given sheet name

for 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 sheet

self.createSheet(fileName, sheetName2)

# defines sheet as the new sheet

sheet = wb.get_sheet(self.getSheetNumber(fileName, sheetName2))

# this writes to the sheet

for colidx, col in enumerate(Stuff):

for rowidx, row in enumerate(col):

sheet.write(rowidx, colidx, row)

# this saves the file

wb.save(fileName2)

總結

以上是生活随笔為你收集整理的python获取excel数据进行判断输出结果到excel,如何使用python xlrd/xlwt从一个excel工作簿提取数据并输出到另一个excel工作簿?...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。