Skip to content
New issue

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

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

Already on GitHub? # to your account

Unable to hide comments if saving using data that already contains VML drawings. #4105

Closed
7 tasks
benstilwell opened this issue Jul 19, 2024 · 2 comments
Closed
7 tasks

Comments

@benstilwell
Copy link

This is:

- [*] a bug report

What is the expected behavior?

When saving a modified spreadsheet with legacyDrawing as xlsx. I expect to still be able to save newly created VMLComments.

What is the current behavior?

Currently when saving a check is made for an existing legacyDrawing and as a result writeVMLComments is never called. This makes it impossible to hide newly created comments.

What are the steps to reproduce?

Have an existing xlsx file containing VML drawings.
Load file and add comments
set visibility of comments to false
Save file and when loading in an excel file reader, the comments are not hidden

<?php

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

// Create new Spreadsheet object
 $excelReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
 $excelData = $excelReader->load($fileWithLegacyDrawing);

$worksheet = $excelData->getSheet(0);
$worksheet->getComment('A2')->getText()->createText("Just Hide Me");      
$worksheet->getComment('A2')->setVisible(false);

$excelWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($excelData, 'Xlsx');
   
$excelWriter->save($newFile);

What features do you think are causing the issue

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

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

Only tested with Xlsx

Which versions of PhpSpreadsheet and PHP are affected?

Currently using php 8,2, PhpSpreadsheet 2.1.0

@oleibman
Copy link
Collaborator

The handling of legacyDrawing is a consequence of PR #3130, which enabled the passing through of form controls if a spreadsheet was loaded and subsequently saved. Your problem is an unintended consequence of that change for spreadsheets with comments but without form controls. There are at least 2 possible approaches to rectifying it. Adding the ability to remove legacyDrawings from worksheets is probably pretty easy. Analyzing the legacyDrawings and automatically removing them if they contain only notes (with no form control elements) is a lot more difficult, but probably a more sensible way to approach the problem. I will add it to my to-do list, but I may not be able to get to it quickly.

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 1, 2024
Fix issue PHPOffice#4105. Passing through form controls from load to save was part of the limited support added with PR PHPOffice#3130. However, the legacyDrawing vml, which is a crucial piece of that change, often contains a description only of notes (comments) with no form control contents. Since legacyDrawing is constructed by Xlsx Writer when it doesn't already exist, Xlsx Reader should not interfere with that ability - it should save the contents of legacyDrawing only when it appears to not consist merely of note descriptions.

It should also be an option to delete the legacyDrawing vml before saving. This allows one to add comments, at the cost of losing form controls. A method `deleteLegacyDrawing` is added to Spreadsheet to permit this.
@oleibman
Copy link
Collaborator

Should be fixed by PR #4122, which is now merged.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

2 participants