Strings outputted not seen by rubyXL
Even if I use use_shared_strings = true, strings outputted by axlsx aren't parsed by rubyXL. I don't know whether it's an axlsx issue or an rubyXL one, so I chose this one at random.
Gemfile
gem 'axlsx', github: 'randym/axlsx'
gem 'rubyXL', github: 'weshatheleopard/rubyXL'
Gemfile.lock
GIT
remote: git://github.com/randym/axlsx.git
revision: 7cf747675097be13df633f1b2a5c45391df52b33
specs:
axlsx (2.0.1)
htmlentities (~> 4.3.1)
nokogiri (>= 1.4.1)
rubyzip (~> 1.1.1)
GIT
remote: git://github.com/weshatheleopard/rubyXL.git
revision: 1bc621b69426cb04104bee96cee4e31be9e7437e
specs:
rubyXL (3.2.3)
nokogiri (>= 1.4.4)
rubyzip (>= 1.1.6)
GEM
specs:
htmlentities (4.3.2)
mini_portile (0.6.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
rubyzip (1.1.6)
PLATFORMS
ruby
DEPENDENCIES
axlsx!
rubyXL!
axlsx_creator.rb
require 'bundler/setup'
require 'axlsx'
# Create a basic Workbook using Axlsx
class AxlsxCreator
WORKBOOK_FILENAME = 'axlsx_output.xlsx'
WORKSHEET_NAME = 'Sheet1'
ROW_DATA = %w(Hello world 42)
def self.run
package = Axlsx::Package.new
workbook = package.workbook
worksheet = workbook.add_worksheet(name: WORKSHEET_NAME)
worksheet.add_row(ROW_DATA)
# This shouldn't be the problem, but doing it just to prove it
package.use_shared_strings = true
package.serialize(WORKBOOK_FILENAME)
end
end
AxlsxCreator.run if File.identical?(__FILE__, $PROGRAM_NAME)
rubyxl_parser.rb
require 'bundler/setup'
require 'rubyXL'
# Parse a basic Workbook
class RubyXLParser
UNMODIFIED_FILENAME = 'axlsx_output.xlsx'
EXCEL_MODIFIED_FILENAME = 'axlsx_output saved excel no modification.xlsx'
def self.run
examine_file(UNMODIFIED_FILENAME)
examine_file(EXCEL_MODIFIED_FILENAME)
end
def self.examine_file(filename)
workbook = RubyXL::Parser.parse(filename)
worksheet = workbook.worksheets.first
cells = worksheet.extract_data
puts "Results with #{filename}"
puts cells.inspect
end
end
RubyXLParser.run if File.identical?(__FILE__, $PROGRAM_NAME)
Results
$ ruby -w bin/axlsx_creator.rb
[irrelevant warning about font_scale]
$ # Open "axlsx_output.xlsx" in Excel, then save it as "axlsx_output saved excel no modification.xlsx"
$ ruby -w bin/rubyxl_parser.rb
[irrelevant warning about column_index]
*** WARNING: storage class not found for docProps/core.xml (http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties)
WARNING: RubyXL::WorkbookRoot is not aware what to do with RubyXL::GenericStorageObject
Results with axlsx_output.xlsx
[["Hello", "world", 42]]
*** WARNING: storage class not found for docProps/core0.xml (http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties)
WARNING: RubyXL::WorkbookRoot is not aware what to do with RubyXL::GenericStorageObject
Results with axlsx_output saved excel no modification.xlsx
[["Hello", "world", 42]]
@oe376, can you please file a bug in RubyXL and provide a sample file with this issue?
@agrimm @weshatheleopard @randym I looked at other implementations. Almost everyone standardizes on the excel way (http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties)
i can confirm this error when generating a xlsx file with axlsx and then parsing it with rubyXL.
*** WARNING: storage class not found for docProps/core.xml (http://schemas.openxmlformats.org/officeDocument/2006/relationships/metadata/core-properties)
it's a simple spec file using shared_strings = true in axlsx
Is there a workaround for this? I am not seeing any strings when I open the .xlsx file generated by the gem in Numbers. Numeric values are fine. String cells are blank!
Confrim too. Mac OS X's Numbers does not show strings in a document generated using axlsx.
Can also confirm. No strings in Numbers, but they are there opening the same file in OpenOffice.
Strings don't show up in Numbers, but if opened in Excel and then saved strings do show up in Numbers, so must be some issue with axlsx ...
Setting use_shared_strings to true fixes this...
Hooray for this issue! I've been searching for hours and couldn't figure out why axlsx generated files won't open in OSX Preview. As said previously, it works with use_shared_strings is set to true.
@constantm me too man.
use_shared_strings works but if it wasn't for this open issue I'd still be banging on the wall...
@oe376: so, according to the standard (ECMA-376 4th edition Part 2 ) the correct namespace for core-properties is http://schemas.openxmlformats.org/package/2006/metadata/core-properties (see page 83 of the PDF document).
P.S. Actually, they fixed it in axlsx already: https://github.com/randym/axlsx/commit/7026a84644cd3fc7dad8c831315bf03dd2493f2a
For those using Numbers: Upgrading from 3.5.x to 3.6.2 fixed it for my machine, for a spreadsheet generated using axlsx 2.0.1, and axlsx_rails 0.4.0.
the core issue remains however: cells with string values in a file generated by axlsx, return nil values if read by rubyxl.
using package.use_shared_strings = true however does allow the axlsx to be readable by rubyxl.
One can also initialize the package like this to become the same result: Axlsx::Package.new(use_shared_strings: true).
Still would consider this to be a bug I guess. It would be nice if the "Known interoperability issues"-section of the readme would mention this problem in the meantime. It could also help future me and others if this section would be linked from the intro of the readme. It's under the changelog now.