Ruby on Rails Excel file formula calculate without any manual interaction - ruby-on-rails

Am trying to use selenium webdriver in ruby on rails for import test case but most of my Excel file has "=Now()" formula so when without open and save that file manually i try to import it showing old date only
Actually am unable to use below mentioned logic in ROR
XSSFWorkbook workbook = new XSSFWorkbook(file);
workbook.setForceFormulaRecalculation(true);
XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook)

Related

Cannot import csv file using neo4j-admin

Hello i am trying to import csv file using neo4j-admin tool but i am receiving this error graph.db' already contains a database
Does this mean that i need to create new database every new import ?
neo4j-admin import is only for creating a new db, it cannot be used to add to an existing db, so you would need to delete your graph.db folder prior to import.
You'll need to use an alternate means, like a LOAD CSV query if you want to add into an existing graph.

How to ignore hidden sheets when importing xlsx files with rails and roo

I am using Roo to import xlsx files into my rails app. The imports work fine, however, while trying to make a 'workbook' importer instead of just a 'worksheet' importer, I noticed that there are tons of hidden sheets on some of the files. For example:
In some of the files the SUB_LABOR sheet has important data that should be imported. These are not hidden. In other files, the SUB_LABOR was used as a scratch pad and then hidden so that people using the sheet will not use it.
I would like my importer to read in the workbook and parse the sheets that are not hidden and ignore the ones that are. I see that the 'hidden' value is stored in the excelx object under <Nokogiri::XML::Attr:[a hex value] name="state" value="hidden">
Is there a way to dig this information out of the object and act on it?
The whole object is way to big to post here.
You can pass in
only_visible_sheets: true
to the initializer, e.g.:
Roo::Excelx.new("my.xlsx", only_visible_sheets: true)

How to write into excel file using ant script

I have a excel file, with some column like this
Name DateTime (if value datetime existing then do not thing)
Jonh 16/07/2015 9:30 (dd/MM/yyyy hh:mm) => date in system
Jonh 16/07/2015 10:30
The question : are there any way to write some sciprt ant to update excel file with two properties : Name and DateTime
When i run script ant, it's could be write new next row
Jond 16/07/2015 11:30
Thanks.
I would suggest using an Excel manipulation library such as Apache POI called from a custom task or a JDBC driver for Excel, using the SQL task to update the XLS file.
This is not a trivial problem to solve. The following example uses a groovy script leveraging Apache POI to read/write Excel files:
Using apache ant commands to store value to excel cell
store ANT regex in an excel file

How create XLSX file from LibXML::XML::Document in Ruby?

My code prepares a string containing XML data in UTF-8 encoding. I use LibXML to create it and finally I call Rails send_data which creates some.xls file from the prepared string. MS Excel perfectly opens the some.xls file, but it's the only application which can open an XML file in table format.
Does anybody know how to create an XLSX file from LibXML::XML::Document? I need to create a spreadsheet at once,not cell by cell.
I checked some gems like XlsxWriter,etc. However, I found the only examples use methods writing into a cell or a row o a column, but I need to create a file at once.
Take a look the axlsx gem, I think this will help you.
https://github.com/randym/axlsx

Write in an existing Excel .xls file which contains macros

I want to insert datas an existing Excel (.xls) file with Ruby under Linux. This file has already data, it has some format properties and it contains macros.
I tried to insert data into the file with the spreadsheet gem but when I save modifications, the format and all the macros of the file are lost.
Here's an example of a simple modification where I meet this problem :
book = Spreadsheet.open('myOriginalFile.xls')
sheet = book.worksheet 0
sheet.write('C12','hello')
book.write('myModifiedFile.xls')
I tried lots of things, did research on forums and the web but I didn't find a solution...
Does anyone has an idea?
I found a solution :
I use the POI library of Apache which is written in java with the rjb gem (Ruby Java Bridge, which allows to use java libraries with ruby). POI allows to keep macros and formulas of existing xls file and to modify it.
For those who need, here's how to set up rjb to use POI :
# JVM loading
apache_poi_path = File.dirname(__FILE__)+'/poi-3.8/poi-3.8-20120326.jar'
Rjb::load("#{apache_poi_path}", ['-Xmx512M'])
# Java classes import
#file_class = Rjb::import('java.io.FileOutputStream')
#workbook_class = Rjb::import('org.apache.poi.hssf.usermodel.HSSFWorkbook')
#poifs_class = Rjb::import('org.apache.poi.poifs.filesystem.POIFSFileSystem')
Rjb::import('org.apache.poi.hssf.usermodel.HSSFCreationHelper')
Rjb::import('org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator')
#cell_reference_class = Rjb::import('org.apache.poi.hssf.util.CellReference')
#cell_class = Rjb::import('org.apache.poi.hssf.usermodel.HSSFCell')
# You can import all java classes that you need
# Java classes utilisation :
#file_input_class = Rjb::import('java.io.FileInputStream')
#file_input = #file_input_class.new(model_file_path)
#fs = #poifs_class.new(#file_input)
#book = #workbook_class.new(#fs)
#worksheet = #book.getSheet('worksheet')
# ...
# You can use your objects like in Java but with a ruby syntax
You need to write the modified file to a new file name. Check out this
If you have more than one sheet, you need to rewrite other sheets
XLS with several sheets but only modify one of the sheets (and don't
touch the other data), there is no way, that spreadsheet "remembers"
what is in the other sheets. You will have to write the unmodified
sheets as well or otherwise unexpected things will happen.
Ergo: Write the modified sheet and also write the complete unmodified
sheets again, when modifying an XLS with spreadsheet with several
sheets.
Might want to check out Axlsx not sure if it will be able to edit a plain .xls, but I did some work with it a few weeks ago, it worked wonders for the xlsx I was working with.
You just need to open existing file, write your changes into file and save it with another name.
For example on server you have template.xls file.
Simple working example ( need to have template.xls near your .rb file ):
#edit_xls.rb
require 'rubygems'
require 'spreadsheet'
book = Spreadsheet.open 'template.xls'
sheet = book.worksheet 0
sheet[0,0] = 'qweqeqw'
book.write 'edited.xls'

Resources