[英]Row updation in xls through python
我想自動增加行號(此處為0到4)並填充一些值(此處為Name)。 但是我只用xls編寫了最后一行的值。
我必須進行更改,以便我將獲得所有行(其值為0到4)。
import xlwt
row_no=0
def xls_write(row_no):
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Result")
Name = "Name is "
sheet1.write(row_no, 0,Name)
book.save("C:/Users/nirajk/Desktop/Row_checking.xls")
print "Current row_no is : " , row_no
xls_write(row_no)
row_no+=1
xls_write(row_no)
row_no+=1
xls_write(row_no)
row_no+=1
xls_write(row_no)
row_no+=1
xls_write(row_no)
我想我了解您要嘗試執行的操作,但對xlwt庫不熟悉,因此如果它不能完全解決問題,應該可以使您朝正確的方向發展。
編輯:展開每個單元格中的可變文本
import xlwt
def xls_write(text, number_of_rows):
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Result")
for i in range(number_of_rows):
sheet1.write(i, 0, text[i])
print "Current row_no is : ", i
print "Text is : ", text[i]
book.save("C:/Users/nirajk/Desktop/Row_checking.xls")
words = ["cat", "dog", "horse", etc]
xls_write(words, len(words))
為了回答這個問題,我使用了openpyxl模塊
import openpyxl
Scene_Catalogue_file_path = "xls_file_path_and_name.xls"
wb = openpyxl.load_workbook(Scene_Catalogue_file_path)
print "All availabe_shhet : ", wb.get_sheet_names()
sheet = wb.get_sheet_by_name('LVDS Recordings') # parsing only specific sheet Recordings
print "B1", sheet['B1'].value
call_no = 1
while(sheet[str('B'+ str(call_no))].value != None):
mention_recording = sheet['B' + str(call_no)].value
Host_Vehicle_static_movie = sheet['C' + str(call_no)].value
Lighting_Condition_poor_good = sheet['D' + str(call_no)].value
Length = sheet['I' + str(call_no)].value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.