openpyxl - 编辑一行的最后一个值
openpyxl - edit the last value of a row
我似乎无法解决这个问题:
我想访问给定列中的最后一个单元格以便为其添加值。但是我的代码不起作用:
from tkinter import *
import datetime
import openpyxl
import os
wb = openpyxl.load_workbook("TimeSheet.xlsx", use_iterators=True)
ws1 = wb.get_sheet_by_name("TimeSheet")
master = Tk()
firstDate = Entry(master)
firstDate.pack()
firstDate.focus_set()
def date_receiving():
totalRows = 0
receivingDate = firstDate.get()
for rowNum in ws1.iter_rows("B6:B"+str(ws1.max_row)):
for cell in rowNum:
print(cell)
cellule = ws1.cell(row=rowNum, column=2).value
if cellule != "":
totalRows += 1
print(totalRows)
else:
break
我尝试了一些方法,但找不到最后一个空单元格。请帮忙!
谢谢,
这里有一些代码可以让你得到最后一个空单元格的编号 maxBlank
。让我知道它是如何为你工作的。
from Tkinter import *
import datetime
import openpyxl
import os
wb = openpyxl.load_workbook("TimeSheet.xlsx", use_iterators=True)
ws1 = wb.get_sheet_by_name("TimeSheet")
master = Tk()
firstDate = Entry(master)
firstDate.pack()
firstDate.focus_set()
def date_receiving():
maxBlank = -1
for rowNum in ws1.iter_rows("B6:B"+str(ws1.max_row)):
for cell in rowNum:
if cell.internal_value == None:
if cell.row > maxBlank:
maxBlank = cell.row
print maxBlank
我似乎无法解决这个问题:
我想访问给定列中的最后一个单元格以便为其添加值。但是我的代码不起作用:
from tkinter import *
import datetime
import openpyxl
import os
wb = openpyxl.load_workbook("TimeSheet.xlsx", use_iterators=True)
ws1 = wb.get_sheet_by_name("TimeSheet")
master = Tk()
firstDate = Entry(master)
firstDate.pack()
firstDate.focus_set()
def date_receiving():
totalRows = 0
receivingDate = firstDate.get()
for rowNum in ws1.iter_rows("B6:B"+str(ws1.max_row)):
for cell in rowNum:
print(cell)
cellule = ws1.cell(row=rowNum, column=2).value
if cellule != "":
totalRows += 1
print(totalRows)
else:
break
我尝试了一些方法,但找不到最后一个空单元格。请帮忙!
谢谢,
这里有一些代码可以让你得到最后一个空单元格的编号 maxBlank
。让我知道它是如何为你工作的。
from Tkinter import *
import datetime
import openpyxl
import os
wb = openpyxl.load_workbook("TimeSheet.xlsx", use_iterators=True)
ws1 = wb.get_sheet_by_name("TimeSheet")
master = Tk()
firstDate = Entry(master)
firstDate.pack()
firstDate.focus_set()
def date_receiving():
maxBlank = -1
for rowNum in ws1.iter_rows("B6:B"+str(ws1.max_row)):
for cell in rowNum:
if cell.internal_value == None:
if cell.row > maxBlank:
maxBlank = cell.row
print maxBlank