Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/document properties namespaces #460

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fasta
Copy link

@fasta fasta commented Jul 18, 2024

Hello, we have encountered a bug with rubyXL which appears to have been reported already. We have forked the project and created a pull request. If you'd like some changes before merging the pull request, please let us know.

Fixes Issue #332

The error reported in #332 was caused by editing a xlsx file with very minimal extended document properties. For example a xlsx file with the following docProps/app.xml:

 <?xml version="1.0" encoding="utf-8"?>
    <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
      <Application>DevExpress Office File API/24.1.3.0</Application>
      <AppVersion>24.1</AppVersion>
    </Properties>

RubyXL currently adds the worksheet count to the extended document properties, but uses only the namespaces defined in the original file (see lib/rubyXL/objects/ooxml_object.rb:315). This leads to an invalid app.xml, because in the original file the "vt" namspace is not defined.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
  <HeadingPairs>
    <vt:vector baseType="variant" size="2">
      <vt:variant>
        <vt:lpstr>Worksheets</vt:lpstr>
      </vt:variant>
      <vt:variant>
        <vt:i4>1</vt:i4>
      </vt:variant>
    </vt:vector>
  </HeadingPairs>

This pull request fixes the issue, so the default namespaces for the document properties object are always set (xmlns && xmlns:vt). Should the document define additional namespaces (or different hrefs for the prefixes) the values of the document are preferred to the default ones (like before).

Related to Issue #446

This error is just a re-report. So this pull request should fix the underlying cause as well. But the attached xlsx file (rubyxl_issue_332_example.xlsx) is already corrupted (meaning the "vt" namespace is missing), and because of this still causes an error:

lib/rubyXL/objects/ooxml_object.rb:152:in `block in parse': undefined method `href' for nil:NilClass (NoMethodError)

Maybe this could be fixed, but considering Excel shows an alert when opening the file, it might be better to just keep the error, so it does not go unnoticed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant