Method: WordWps::Text#chart
- Defined in:
- lib/word_wps.rb
#chart(tbl, &block) ⇒ Object
绘制图表测试图表tbl = [
["a", "1"],
["b", "2"],
["c", "3"],
["d", "4"],
] text.chart(tbl) do |chart|
chart.title = "Name"
chart.type = 5
#chart.axes_x = "year"
#chart.axes_y = "value"
chart.style = 251
end
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/word_wps.rb', line 367 def chart(tbl, &block) begin excel = ExcelWps::WorkBook.new #excel.show excel.display_alerts = false worksheet = excel.add_worksheet("sheet") tbl.each do |r| worksheet.add_row { |row| row << r } end # 获取结束的单元格 col = tbl[0].size end_cell = worksheet.current_row.cell_name(col - 1) worksheet.add_chart do |chart| chart.source = worksheet.range("A1:#{end_cell}") block.call(chart) end ensure excel.close end self.style("正文") self.center doc_work.Application.Selection.PasteAndFormat(13) # 移动到下一行 self.move_down self.left end |