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

Comments will not be read #3665

Closed
7 tasks
GooseDL opened this issue Aug 1, 2023 · 2 comments · Fixed by #3668
Closed
7 tasks

Comments will not be read #3665

GooseDL opened this issue Aug 1, 2023 · 2 comments · Fixed by #3668

Comments

@GooseDL
Copy link

GooseDL commented Aug 1, 2023

This is:

- [ X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

Return comments into a cell

What is the current behavior?

Return empty comments

What are the steps to reproduce?

First of all, sorry for my poor English.

If relationships Targets are defined as full paths Xlsx::loadSpreadsheetFromFile will not work properly.

Example:
<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells" Target="/xl/tables/tableSingleCells1.xml" Id="R7794038cb2c64bae"/>
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="/xl/comments1.xml" Id="Red2c67a5311c43a9"/>
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing" Target="/xl/drawings/vmldrawing.vml" Id="Re97db53ed0e14c5f"/>
<Relationship Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="/xl/tables/table1.xml" Id="Rc27115a48a714b5e"/>
</Relationships>

This is the way Microsoft Business Central (formerly Navision) exports data to XLSX format.

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$file = "MIG01.xlsx";
$spreadsheet = (PhpOffice\PhpSpreadsheet\IOFactory::createReader(PhpOffice\PhpSpreadsheet\IOFactory::identify($file)))->load($file);
// add code that show the issue here...
echo $spreadsheet->getSheetByName("Cuenta")->getComment("A3")->getText();
// Will show nothing even when you can see "Code20" comment in A3 cell if you open MIG01.xlsx on Excel

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

Sample:
MIG01.xlsx

What features do you think are causing the issue

  • [ X] Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

WA I have used this and It works for me, although I am not sure if it will work right always:
In Reader/Xlsx.php, line 795, just after $fileWorksheet = (string) $worksheets[$sheetReferenceId]; I have added this piece of code:

$fileWorksheet = (string) $worksheets[$sheetReferenceId];
if ($fileWorksheet[0] == "/") {
	$fileWorksheet = substr($fileWorksheet, strlen($dir) + 2);
}

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

xlsx

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet: 1.29.0
php: 8.2.8

@oleibman
Copy link
Collaborator

oleibman commented Aug 1, 2023

Thank you for providing a sample spreadsheet. Your fix is okay as far as it goes. However, it is not the only problem with this spreadsheet. Even with your change, it does not read the Table correctly, because the third party package uses namespacing for Tables which PhpSpreadsheet does not yet expect. So, the complete solution may take a while. As a workaround which might be useful for you, you can open the spreadsheet in Excel and save it as a new spreadsheet; PhpSpreadsheet will not have a problem with the new one.

@GooseDL
Copy link
Author

GooseDL commented Aug 2, 2023 via email

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 3, 2023
Fix PHPOffice#3665. The original issue was the use of an absolute path in the rels file pointing to the comments file. That was easy to take care of, but a bigger problem with the spreadsheet accompanying the problem report was that it used unexpected spacing for AutoFilters and Tables. AutoFilters were already known not to be covered, but Tables appeared after the namespacing changes, but without namespacing support. This PR fixes the absolute path problem and adds namespacing support for Tables and AutoFilters.

Remaining areas which are still namespace unaware, mainly because of the absence of test samples which use them with unexpected namespacing, include conditional formatting (internal or external), sheet view options, sheet protection, unparsed loaded data, data validation (internal or external), alternate content, and header/footer images.
oleibman added a commit that referenced this issue Aug 10, 2023
* Xlsx Reader Namespacing for Tables, AutoFilters

Fix #3665. The original issue was the use of an absolute path in the rels file pointing to the comments file. That was easy to take care of, but a bigger problem with the spreadsheet accompanying the problem report was that it used unexpected spacing for AutoFilters and Tables. AutoFilters were already known not to be covered, but Tables appeared after the namespacing changes, but without namespacing support. This PR fixes the absolute path problem and adds namespacing support for Tables and AutoFilters.

Remaining areas which are still namespace unaware, mainly because of the absence of test samples which use them with unexpected namespacing, include conditional formatting (internal or external), sheet view options, sheet protection, unparsed loaded data, data validation (internal or external), alternate content, and header/footer images.

* Mysterious Warning for Php7.4 Only

Node no longer exists, doesn't affect result. Suppress warning.

* Scrutinizer

What would a change be without some new false positives?

* Scrutinizer

A gift that keeps on giving :-( Now it's deciding that things that it didn't report in a scan from a few minutes ago are worth reporting, even with no relevant code changes.

* Scrutinizer

It is an idiot. Let me see if I can fix one false positive and succeed in guessing where it might report another one, even though it didn't do so with this last run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants