简体   繁体   English

使用Python和xlsxwriter将单元格引用与单元格数量连接起来

[英]Using Python and xlsxwriter to concatenate cell references with cell count

Hi I have a working script to generate a line chart using Xlsxwriter, however I am looking for a way to concatenate an earlier hit count with the cell range for my generated chart as the script is used to iterate over several similar files in the directory so the overall 'hit count' varies for each file. 嗨,我有一个工作脚本,可以使用Xlsxwriter生成折线图,但是我正在寻找一种方法,可以将早期的命中次数与生成的图表的单元格范围连接起来,因为该脚本用于遍历目录中的多个类似文件,因此每个文件的总“点击计数”各不相同。

The script first looks through a text file for a string and collects some stats using line spitting drops the collected figures into Excel and and generates a hit count each time the particular string is found (total) 该脚本首先在文本文件中查找字符串,并使用行分割法收集一些统计信息,将收集到的数字拖放到Excel中,并在每次找到特定字符串时(总)生成点击计数

Then charts are generated using thee collected stats.. 然后使用收集到的统计信息生成图表。

Here's my chart generating section... 这是我的图表生成部分...

chart1 = workbook.add_chart({'type': 'line'})
chart1.add_series({
    'name':       'My Chart',
    'categories': '=Sheet1!$A$2:$A$2200',
    'values':     '=Sheet1!$B$2:$B$2200',
    'line':   {'color': 'purple'},

})

I am hoping to generate the chart by referencing the 'total' count in the row count. 我希望通过引用行计数中的“总数”计数来生成图表。 So I am looking for something along the lines of 所以我正在寻找一些类似的东西

'categories': '=Sheet1!$A$2:$A$'+total,
'values':     '=Sheet1!$B$2:$B$'+total,

I hope this makes sense? 我希望这是有道理的? Basically I am looking to have a varying cell row range dependent on the count of hits, is this possible? 基本上,我希望根据点击数来改变单元格的行范围,这可能吗? Or alternatively is there a 'last row' reference in xlsxwriter for this type of circumstance? 或者,在xlsxwriter中是否存在针对这种情况的“最后一行”引用?

Thanks, MikG 谢谢,MikG

The chart.add_series() method also accepts a list of values so you can do something like this: chart.add_series()方法还接受值列表,因此您可以执行以下操作:

chart1.add_series({
    'name':       'My Chart',
    'categories': ['Sheet1', 1, 0, total -1, 0],
    'values':     ['Sheet1', 1, 1, total -1, 1],
    'line':       {'color': 'purple'},
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM