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

Undefined index: height exception on reading vmlDrawings #1347

Closed
malles opened this issue Feb 4, 2020 · 2 comments · Fixed by #1348
Closed

Undefined index: height exception on reading vmlDrawings #1347

malles opened this issue Feb 4, 2020 · 2 comments · Fixed by #1348

Comments

@malles
Copy link
Contributor

malles commented Feb 4, 2020

This is:

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

Similar closed issue (stale): #888

What is the expected behavior?

Styled vmlDrawings can be read from an xlsx file, or will at least not crash the reader..

What is the current behavior?

In some examples the reader throws exception Undefined index: height on Xlsx.php (line 1048).

What are the steps to reproduce?

I have found this issue in various XLSX files.
Consider an XML with a vmlDrawing like this

<v:shape id="CheckBox3" o:spid="_x0000_s4106" type="#_x0000_t201"
  style='position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt;
  height:13.5pt;z-index:5;mso-wrap-style:tight' fillcolor="white [9]"
  stroked="f" strokecolor="windowText [64]" strokeweight="3e-5mm" o:insetmode="auto">
  <v:fill color2="white [9]"/>
  <v:imagedata o:relid="rId5" o:title=""/>
  <v:shadow color="black" obscured="t"/>
  <x:ClientData ObjectType="Pict">
   <x:SizeWithCells/>
   <x:Anchor>
    42, 1, 13, 1, 46, 28, 13, 19</x:Anchor>
   <x:AutoFill>False</x:AutoFill>
   <x:AutoLine>False</x:AutoLine>
   <x:FmlaLink>Sheet2!E41</x:FmlaLink>
   <x:CF>Pict</x:CF>
   <x:AutoPict/>
   <x:MapOCX/>
  </x:ClientData>
 </v:shape>

The style from the shape is extracted via Xlsx::toCSSArray. Here the newlines are stripped:

$style = trim(str_replace(["\r", "\n"], '', $style), ';');.

As a result, the whitespace from the tab is not trimmed;

position:absolute;margin-left:424.5pt;margin-top:169.5pt;width:67.5pt; height:13.5pt;z-index:5;mso-wrap-style:tight.

This leaves the spaces in the key for height in the resulting style array:
image

This leads to $hfImages[(string) $shape['id']]->setHeight($style['height']); (src) throwing the Undefined index: height exception.

Proposed fix

Also replace the spaces in Xlsx::toCSSArray;

$style = trim(str_replace(["\r", "\n", ' '], '', $style), ';');

Which versions of PhpSpreadsheet and PHP are affected?

Most recent (1.10.1).

malles added a commit to malles/PhpSpreadsheet that referenced this issue Feb 4, 2020
Fixes PHPOffice#1347. Indentation in the xml leaves spaces in style string even after replacing newlines. Replacing the spaces ensures no spaces in keys of the resulting style-array
@malles malles changed the title Undefined index: height exception on reading vmlDrawings Undefined index: height exception on reading vmlDrawings Feb 4, 2020
malles added a commit to malles/PhpSpreadsheet that referenced this issue Feb 4, 2020
@stale
Copy link

stale bot commented Apr 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Apr 4, 2020
PowerKiKi pushed a commit to malles/PhpSpreadsheet that referenced this issue Apr 5, 2020
Indentation in the xml leaves spaces in style string even after
replacing newlines. Replacing the spaces ensures no spaces in keys
of the resulting style-array

Fixes PHPOffice#1347
PowerKiKi pushed a commit that referenced this issue Apr 5, 2020
Indentation in the xml leaves spaces in style string even after
replacing newlines. Replacing the spaces ensures no spaces in keys
of the resulting style-array

Fixes #1347
@malles
Copy link
Contributor Author

malles commented Apr 6, 2020

Thanks!

@oleibman oleibman removed the stale label Jul 19, 2024
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