使用具有背景填充的单元格将列添加到列表
Add columns to lists using cells with Background fill
我组织的成员希望能够对大型信息电子表格进行颜色编码,然后使用(使用 Openpyxl)Python 将这些信息拉入系列列表以插入到 PowerPoint 中(使用 Python-pptx)。我已经能够让除 Series 以外的所有东西都正常工作,它需要一个系列名称和系列数据(组织在可能不相邻的单独列中)。
这是我目前所拥有的
series_count = 2
while series_count <= ws.max_column:
for s in range(2, ws.max_column + 1):
series_list = []
series_name = ws.cell(4, series_count).value
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.value != series_name:
series_list.append(cell.value)
chart_data.add_series(series_name, series_list, '0%') #Meant to take the series_name and series_list and create a chart using python-pptx
series_count += 1
这只会抓取一个系列,不会将其插入到图表数据中。我没有遇到任何异常,但是当打开 PowerPoint 文档时,只有空白图表字段。
如果数据在相邻的列中,我可以手动设置范围,但这在长期内是不可行的。
series_count = 2
while series_count <= ws.max_column:
for s in range(2, ws.max_column + 1):
series_list = []
series_name = ws.cell(4, series_count).value
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.value != series_name:
series_list.append(cell.value)
chart_data.add_series(series_name, series_list, '0%')
series_count += 1
我是新手,所以我很乐意考虑使用其他方法来解决这个问题,这些方法可以在我的技术水平更低的同事的投入最少的情况下实现相同的结果。 (他们可以管理颜色,但其他格式效果不佳。)
感谢您的帮助!
这段代码似乎对我有用。
series_count = 2
while series_count <= ws.max_column: #searches sheet for color-coded data and pulls it into series.
for s in range(2, ws.max_column + 1):
series_list = []
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.fill.start_color.index == 9:
series_list.append(cell.value)
elif cell.fill.start_color.index == 8:
series_name = cell.value
else:
pass
if len(series_list) > 0:
print "Adding", series_name, series_list
chart_data.add_series(series_name, series_list, '0%')
else:
pass
series_count += 1
感谢您的协助!
我组织的成员希望能够对大型信息电子表格进行颜色编码,然后使用(使用 Openpyxl)Python 将这些信息拉入系列列表以插入到 PowerPoint 中(使用 Python-pptx)。我已经能够让除 Series 以外的所有东西都正常工作,它需要一个系列名称和系列数据(组织在可能不相邻的单独列中)。
这是我目前所拥有的
series_count = 2
while series_count <= ws.max_column:
for s in range(2, ws.max_column + 1):
series_list = []
series_name = ws.cell(4, series_count).value
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.value != series_name:
series_list.append(cell.value)
chart_data.add_series(series_name, series_list, '0%') #Meant to take the series_name and series_list and create a chart using python-pptx
series_count += 1
这只会抓取一个系列,不会将其插入到图表数据中。我没有遇到任何异常,但是当打开 PowerPoint 文档时,只有空白图表字段。
如果数据在相邻的列中,我可以手动设置范围,但这在长期内是不可行的。
series_count = 2
while series_count <= ws.max_column:
for s in range(2, ws.max_column + 1):
series_list = []
series_name = ws.cell(4, series_count).value
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.value != series_name:
series_list.append(cell.value)
chart_data.add_series(series_name, series_list, '0%')
series_count += 1
我是新手,所以我很乐意考虑使用其他方法来解决这个问题,这些方法可以在我的技术水平更低的同事的投入最少的情况下实现相同的结果。 (他们可以管理颜色,但其他格式效果不佳。)
感谢您的帮助!
这段代码似乎对我有用。
series_count = 2
while series_count <= ws.max_column: #searches sheet for color-coded data and pulls it into series.
for s in range(2, ws.max_column + 1):
series_list = []
for c in range(4, ws.max_row + 1):
cell = ws.cell(row = c, column = series_count)
if cell.fill.start_color.index == 9:
series_list.append(cell.value)
elif cell.fill.start_color.index == 8:
series_name = cell.value
else:
pass
if len(series_list) > 0:
print "Adding", series_name, series_list
chart_data.add_series(series_name, series_list, '0%')
else:
pass
series_count += 1
感谢您的协助!