python - 如何修复 Python Visio 转换器中的 for 循环
问题描述
我正在尝试运行一个 for 循环,但是当它到达某个日期时让它停止,它会这样做,但是,当我只想要 1 时,它会在彼此之上打印出多个形状。程序以某种方式打印数字形状基于它在 Excel 中的行号。不知道如何解决这个问题,任何帮助将不胜感激。
from PIL import Image, ImageDraw, ImageFont
import win32com.client
from win32com.client import constants as vis
app = win32com.client.gencache.EnsureDispatch( 'Visio.Application' )
current = datetime.datetime(*xlrd.xldate_as_tuple(sheet3.cell_value(7,9), wb.datemode))
currentDate = current.strftime('%m/%d')
dateList = []
for row in range(1,sheet3.nrows):
if sheet3.cell_value(row,13) == "":
continue
date = datetime.datetime(*xlrd.xldate_as_tuple(sheet3.cell_value(row,13), wb.datemode))
dateList.append(date.strftime('%m/%d'))
for date in dateList:
x1 = sheet3.cell_value(row,14)
x2 = sheet3.cell_value(row,15)
y1 = sheet3.cell_value(row,16)
y2 = sheet3.cell_value(row,17)
borderColor = 0
borderType = 0
colorValue = sheet3.cell_value(9,10)
colorFunc(x1,y1,x2,y2)
shape.Cells('FillforegndTrans').FormulaU = sheet3.cell_value(7,10)
if currentDate == date:
break
解决方案
我已经想通了。而不是一个for循环,我只需要在最后声明一个if语句,如果currentDate在dateList中,然后break。
dateList = []
for row in range(1,sheet3.nrows):
if sheet3.cell_value(row,13) == "":
continue
date = datetime.datetime(*xlrd.xldate_as_tuple(sheet3.cell_value(row,13), wb.datemode))
dateList.append(date.strftime('%m/%d'))
current = datetime.datetime(*xlrd.xldate_as_tuple(sheet3.cell_value(7,9), wb.datemode))
currentDate = current.strftime('%m/%d')
x1 = sheet3.cell_value(row,14)
x2 = sheet3.cell_value(row,15)
y1 = sheet3.cell_value(row,16)
y2 = sheet3.cell_value(row,17)
borderColor = 0
borderType = 0
colorValue = sheet3.cell_value(9,10)
colorFunc(x1,y1,x2,y2)
shape.Cells('FillforegndTrans').FormulaU = sheet3.cell_value(7,10)
if currentDate in dateList:
break
推荐阅读
- c - 如何使用 argv 生成所有可能的密码组合列表?
- ios - Xcode:在嵌入式框架中找不到模块
- python - ~~在启动时运行 Python 脚本会打开 Chrome 导致意外问题~~ 已解决多线程问题
- python - 简单插补模型 n_feature 和输入 n_feature 不匹配
- c# - 我们如何从 Microsoft Office 加载项调用 Invoke(Delegate) 方法?
- javascript - 如何在javascript中的JSON对象声明中跳过或将参数传递到子节点
- ios - 如何在 swift iOS 应用程序中调用分支初始化
- php - 如何实现流的 Boyer-Moore 搜索
- c# - c# string.GetHashCode。唯一号码生成
- java - 如何使用 for 循环在数组中运行一行