对于如何将行col转换为A1表示法并在add_series()
方法中将其用于XlsxWriter中的图表,我并不感兴趣。
请参阅以下代码以供参考:
print "Drawing Simultaneous Busy Cores"
writer.targetWrite('simultaneous_busy_cores', 'weighted_average', *write_data)
row = writer.getRow('simultaneous_busy_cores')
str1_cat = xl_rowcol_to_cell(6, 1, row_abs=True, col_abs=True)
str2_cat = xl_rowcol_to_cell(6, 8, row_abs=True, col_abs=True)
str1_val = xl_rowcol_to_cell(row-1, 1, row_abs=True, col_abs=True)
str2_val = xl_rowcol_to_cell(row-1, 8, row_abs=True, col_abs=True)
print str1_cat
print str2_cat
print str1_val
print str2_val
dict_series = {
'name': 'simultaneous_busy_cores',
'categories': '=simultaneous_busy_cores!str1_cat:str2_cat',
'values': '=simultaneous_busy_cores!str1_val:str2_val',
'data_labels': {'percentage': True, }
}
chart1.add_series(dict_series)
chart1.set_title({'name': 'simultaneous_busy_cores'})
chart1.set_style(10)
target_sheet.insert_chart('K2', chart1, {'x_offset': 25, 'y_offset': 10})
str_cat和str_val的值为:
Drawing Simultaneous Busy Cores
$B$7
$I$7
$B$24
$I$24
TIA欢迎任何帮助!
答案 0 :(得分:2)
要回答直接问题,您可以使用string.format()
或%
将变量值插入字符串中:
'=simultaneous_busy_cores!%s:%s' % (str1_cat, str2_cat),
然而,由于XlsxWriter已经支持类别和值的列表语法,因此这项工作比必要的更多:
dict_series = {
'name': 'simultaneous_busy_cores',
'categories': ['simultaneous_busy_cores', 6, 1, 6, 8],
'values': ['simultaneous_busy_cores', row-1, 1, row-1],
'data_labels': {'percentage': True, }
}
有关详细信息,请参阅add_series()
上的文档。