axlsx icon indicating copy to clipboard operation
axlsx copied to clipboard

Strings outputted not seen by rubyXL

Open agrimm opened this issue 11 years ago • 12 comments

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]]

agrimm avatar Sep 02 '14 07:09 agrimm

@oe376, can you please file a bug in RubyXL and provide a sample file with this issue?

weshatheleopard avatar Sep 05 '14 03:09 weshatheleopard

@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)

oe376 avatar Sep 05 '14 15:09 oe376

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

dfherr avatar Sep 08 '14 11:09 dfherr

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!

martinstreicher avatar Nov 20 '14 21:11 martinstreicher

Confrim too. Mac OS X's Numbers does not show strings in a document generated using axlsx.

907th avatar Mar 05 '15 19:03 907th

Can also confirm. No strings in Numbers, but they are there opening the same file in OpenOffice.

mkon avatar Mar 09 '15 10:03 mkon

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...

humancopyright avatar May 02 '15 17:05 humancopyright

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 avatar Jun 16 '15 20:06 constantm

@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...

goncalvesjoao avatar May 04 '16 13:05 goncalvesjoao

@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

weshatheleopard avatar May 04 '16 18:05 weshatheleopard

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.

agrimm avatar May 23 '16 02:05 agrimm

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.

caifara avatar Dec 14 '17 12:12 caifara