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

Reading file information such as author #17

Open
Roeya opened this issue Jul 9, 2024 · 7 comments
Open

Reading file information such as author #17

Roeya opened this issue Jul 9, 2024 · 7 comments

Comments

@Roeya
Copy link

Roeya commented Jul 9, 2024

thank you for this great module, I would like the help you improve it a bit

In the source you have a remarked place holder for the author of the file at line 134:
# $workbook->{Author} = ...;

please add the code to read the author etc from the XLSX file:

 my $core = $self->_parse_xml($zip, "docProps/core.xml");
 my ($creator) = $core->find_nodes('//dc:creator'); 
 $workbook->{Author}  = $creator->first_child()->dcdata;

This is a bit naive code, but I do not know XML::Twig well enough...

@MichaelDaum
Copy link
Owner

Would you like to create a pull request? Thanks in advance.

@Roeya
Copy link
Author

Roeya commented Jul 9, 2024 via email

@asb-capfan
Copy link

Please find PR #20 for this change.

@MichaelDaum
Copy link
Owner

I tried PR #20, alas the unit tests in author.t fail.

@asb-capfan
Copy link

Hm, I'm sorry. It worked on my machine(tm). I confirmed with prove -l.

What kind of errors do you get? More details might be helpful.

When using dzil test --release, I did get some "Failed test 'No incorrect line endings in 't/basic.t' on line 1: [\r]'" for my test. I converted my t file to UNIX line endings and now they are gone.
There is some other messages about other tests but I don't know how to fix them.

The results now are as follows:

spreadsheet-parsexlsx>prove -lv
t\ahihi.t .....................
ok 1 - An object of class 'Spreadsheet::ParseExcel::Workbook' isa 'Spreadsheet::ParseExcel::Workbook'
1..1
ok
t\author-attribute-in-xlsx.t ..
ok 1 - Author extracted for t/data/author_single.xlsx
ok 2 - Correct author for t/data/author_single.xlsx
ok 3 - Author extracted for t/data/author_multiple.xlsx
ok 4 - Correct author for t/data/author_multiple.xlsx
ok 5 - No author extracted for t/data/author_none.xlsx
ok 6 - No author extracted for t/data/author_invalid_core.xlsx
1..6
ok
...
spreadsheet-parsexlsx>dzil test --release
[←[38;5;199mDZ←[0m] building distribution under .build/b_LPG6fUfl for installation
[←[38;5;199mDZ←[0m] beginning to build Spreadsheet-ParseXLSX
[←[38;5;33mGit::NextVersion←[0m] Bumping version from 0.36 to 0.37
[←[38;5;199mDZ←[0m] guessing dist's main_module is lib/Spreadsheet/ParseXLSX.pm
[←[38;5;73mExtraTests←[0m] rewriting author test xt/author/no-tabs.t
[←[38;5;73mExtraTests←[0m] rewriting author test xt/author/eol.t
[←[38;5;73mExtraTests←[0m] rewriting author test xt/author/critic.t
[←[38;5;73mExtraTests←[0m] rewriting author test xt/author/pod-coverage.t
[←[38;5;73mExtraTests←[0m] rewriting author test xt/author/pod-syntax.t
[←[38;5;43mGit::Contributors←[0m] multiple emails with the same name found: you may want to use a .mailmap file (https://www.kernel.org/pub/software/scm/git/docs/git-shortlog.html#_mapping_authors):
[Git::Contributors]   alex
[←[38;5;199mDZ←[0m] writing Spreadsheet-ParseXLSX in .build/b_LPG6fUfl
[←[38;5;134mReadmeAnyFromPod←[0m] overriding README.md in root
Checking if your kit is complete...
Looks good
Generating a gmake-style Makefile
Writing Makefile for Spreadsheet::ParseXLSX
Writing MYMETA.yml and MYMETA.json
cp lib/Spreadsheet/ParseXLSX/Decryptor.pm blib\lib\Spreadsheet\ParseXLSX\Decryptor.pm
cp lib/Spreadsheet/ParseXLSX/Cell.pm blib\lib\Spreadsheet\ParseXLSX\Cell.pm
cp lib/Spreadsheet/ParseXLSX/Decryptor/Standard.pm blib\lib\Spreadsheet\ParseXLSX\Decryptor\Standard.pm
cp lib/Spreadsheet/ParseXLSX/Decryptor/Agile.pm blib\lib\Spreadsheet\ParseXLSX\Decryptor\Agile.pm
cp lib/Spreadsheet/ParseXLSX.pm blib\lib\Spreadsheet\ParseXLSX.pm
cp lib/Spreadsheet/ParseXLSX/Worksheet.pm blib\lib\Spreadsheet\ParseXLSX\Worksheet.pm
"C:\Strawberry\perl\bin\perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib\lib', 'blib\arch')" t/*.t
t/00-compile.t ................ ok
t/author-attribute-in-xlsx.t .. ok
t/author-critic.t ............. Could not parse profile ".perlcriticrc": Failed to open file '.perlcriticrc' for reading: No such file or directoryCould not parse profile ".perlcriticrc": Failed to open file '.perlcriticrc' for reading: No such file or directoryCould not parse profile ".perlcriticrc": Failed to open file '.perlcriticrc' for reading: No such t/author-critic.t ............. Dubious, test returned 1 (wstat 256, 0x100)
Failed 6/6 subtests
t/author-eol.t ................ 1/?
#   Failed test 'No incorrect line endings in 't/basic.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-10.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-11.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-12.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-13.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-14.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-15.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-16.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-17.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-2.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-29.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-3.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-32.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-38.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-4.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-41.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-5.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-57.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-6-2.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-6.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-61.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-7.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-72.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-8.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-md-10.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-md-11.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/bug-md-7.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/cell-to-row-col.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/column-formats.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/encryption.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/garbage-collect.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/hidden-row-and-column.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/hidden-sheet.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/hyperlinks.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/page-Setup.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/rich.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/tab-color.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]

#   Failed test 'No incorrect line endings in 't/target-abspath.t' on line 1: [\r]'
#   at t/author-eol.t line 71.
#   Problem Lines:
# line 1: [\r]: #!/usr/bin/env[\s]perl[\r]
# Looks like you failed 38 tests of 51.
t/author-eol.t ................ Dubious, test returned 38 (wstat 9728, 0x2600)
Failed 38/51 subtests
t/author-no-tabs.t ............ ok
t/author-pod-coverage.t ....... ok
t/author-pod-syntax.t ......... ok
t/basic.t ..................... ok
t/bug-10.t .................... ok
t/bug-11.t .................... ok
t/bug-12.t .................... ok
t/bug-13.t .................... ok
t/bug-14.t .................... ok
t/bug-15.t .................... ok
t/bug-16.t .................... ok
t/bug-17.t .................... ok
t/bug-2.t ..................... ok
t/bug-29.t .................... ok
t/bug-3.t ..................... ok
t/bug-32.t .................... ok
t/bug-38.t .................... ok
t/bug-4.t ..................... ok
t/bug-41.t .................... ok
t/bug-5.t ..................... ok
t/bug-57.t .................... ok
t/bug-6-2.t ................... ok
t/bug-6.t ..................... ok
t/bug-61.t .................... ok
t/bug-7.t ..................... ok
t/bug-72.t .................... ok
t/bug-8.t ..................... ok
t/bug-md-10.t ................. ok
t/bug-md-11.t ................. ok
t/bug-md-7.t .................. ok
t/cell-to-row-col.t ........... ok
t/column-formats.t ............ ok
t/encryption.t ................ ok
t/garbage-collect.t ........... ok
t/hidden-row-and-column.t ..... ok
t/hidden-sheet.t .............. ok
t/hyperlinks.t ................ ok
t/page-Setup.t ................ ok
t/rich.t ...................... ok
t/tab-color.t ................. ok
t/target-abspath.t ............ ok

Test Summary Report
-------------------
t/author-critic.t           (Wstat: 256 Tests: 0 Failed: 0)
  Non-zero exit status: 1
  Parse errors: Bad plan.  You planned 6 tests but ran 0.
t/author-eol.t              (Wstat: 9728 Tests: 51 Failed: 38)
  Failed tests:  14-51
  Non-zero exit status: 38
t/hyperlinks.t              (Wstat: 0 Tests: 58 Failed: 0)
  TODO passed:   47-49, 51-53, 55-57
Files=45, Tests=1409, 57 wallclock secs ( 0.11 usr +  0.08 sys =  0.19 CPU)
Result: FAIL
Failed 2/45 test programs. 38/1409 subtests failed.
gmake: *** [Makefile:898: test_dynamic] Error 255
error running gmake test

@asb-capfan
Copy link

For reference, this is the code change, if someone wants to implement it:

  # $workbook->{Author} = ...;
  # Extract the author from docProps/core.xml
  {
    my $core;
    eval {
      $core = $self->_parse_xml($zip, "docProps/core.xml");
    };
    if ($@) {
      #warn "Error parsing core.xml: $@\n";
      $workbook->{Author} = undef;  # Set Author to undef if parsing fails
    } elsif ($core) {
      my ($creator_node) = $core->find_nodes('//dc:creator');
      if ($creator_node) {
        $workbook->{Author} = $creator_node->text;
      } else {
        $workbook->{Author} = undef;  # No author found
      }
    } else {
      $workbook->{Author} = undef;  # core.xml missing or unreadable
    }
  }

@MichaelDaum
Copy link
Owner

MichaelDaum commented Jan 26, 2025

I've used prove t/author.t. My guess was that the example xlsx files actually didn't contain the author information it was testing for. I'd really like to re-apply your pull requests with tests fixed.

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

No branches or pull requests

3 participants