I have an Excel document. I want access graphical objects(such as charts, diagrams, images etc) and store it in ruby variables. Tried the same with Spreadsheet and roo gem, but ths gems does not support accessing graphical objects.
Please help.
I have an Excel document. I want access graphical objects(such as charts, diagrams, images etc) and store it in ruby variables. Tried the same with Spreadsheet and roo gem, but ths gems does not support accessing graphical objects.
Please help.
从 Ruby 访问 Excel 数据可能有点痛苦。我建议您从 Excel 工作表中导出/导入原始数据,并使用一些 JavaScript 库构建图表,例如:
您可以将Apache POI与 gem rjb一起使用。
安装:
$ sudo apt-get install openjdk-6-jre-headless openjdk-6-jdk
$ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
$ sudo apt-get install ant
$ gem install "rjb"
利用:
require 'rjb'
#RJM Loading
JARS = Dir.glob('./jar/*.jar').join(':')
Rjb::load(JARS, ['-Xmx512M'])
# Classes:
# Java
file_input_class = Rjb::import('java.io.FileInputStream')
file_output_class = Rjb::import('java.io.FileOutputStream')
byte_array_output_class = Rjb::import('java.io.ByteArrayOutputStream')
# POI
workbook_factory_class = Rjb::import('org.apache.poi.ss.usermodel.WorkbookFactory')
file_in_path = "./chart1.xlsx"
file_in = file_input_class.new(file_in_path)
wb = workbook_factory_class.create(file_in)
sheet = wb.getSheetAt(0)
charts = sheet.createDrawingPatriarch().getCharts()
p chart1.getClass().getName() # First chart's name