Skip to content

Support for LegacyDrawing #1770

@tchari

Description

@tchari

This is:

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

I'm using Excel 2019, php 7.4, and the master branch of PhpSpreadsheet

It seems as though the Xlsx Reader does not read the legacyDrawing element. If you read in an xlsm that contains a FormControl button and then save the spreadsheet, the button will be missing when you open the newly saved file. If you unzip the newly saved file, add back the missing legacyDrawing element, and re-zip then the button will be available.

What is the expected behavior?

The saved xlsm retains the button

What is the current behavior?

The saved xlsm no longer has the button

What are the steps to reproduce?

  1. Open Excel 2019
  2. Create a blank workbook
  3. Add a button -> click the Developer tab, then Insert, then select the box icon under Form Controls
  4. In the AssignMacro window, record a new marco. Use the default values. The recorded macro can be whatever you want. I just clicked a random cell and gave it a fixed value (e.g. the character 'a').
  5. Save the file anywhere you want and call it 'test.xlsm'.
  6. Run the code below:
<?php

require __DIR__ . '/vendor/autoload.php';
$reader = new XlsxReader();
$sheet = $reader->load('path/to/test.xlsm');
$writer = new XlsxWriter($sheet);
$writer->save('path/to/test_2.xlsm');
  1. Open 'test_resaved.xlsm' and you'll find there is no button.

Optional

  1. Unpack both test.xlsm and test_resaved.xlsm using your favorite unzip program (I used WinRAR)
  2. Open and compare path/to/test/xl/worksheet/sheet1.xml and path/to/test_resaved/xl/worksheet/sheet1.xml
  3. Somewhere in the file you'll find an element called <drawing> and they will be the same in both files
  4. In the test version of sheet1.xml you'll also find a <legacyDrawing> element. That element will be missing from the test_resaved version.
  5. Copy-paste the legacy drawing element
  6. Recreate test_resaved.xlsm by zipping everything up again (I used WinRAR, fastest)
  7. Open test_resaved.xlsm and you see the button.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions