PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.35k stars 3.47k forks source link

Documentation - clarifying X/Y and X2/Y2 #3000

Open rolinger opened 2 years ago

rolinger commented 2 years ago

This is:

- [ ] a bug report
- [ ] a feature request
- [x ]  Documentation

For drawings, could you please clarify what setCoordinate() and setCoordinates2() are? Same for setOffsetX/Y and setOffsetX2/Y2? I am confused by duplication of these methods?

The docs don't tell what each is. And in the example scripts I see setCoordinates('C9') followed by setCoordinates2('C9') - at first I thought they were top/bottom X1('C9') & X2('C15') or left/right Y1('H9') & Y2('H15') - but being set to the same value doesn't make sense.

In this example: https://github.com/PHPOffice/PhpSpreadsheet/blob/master/samples/Basic/48_Image_move_size_with_cells.php

$drawing2->setCoordinates('C2');  // why the same as the next line?
$drawing2->setCoordinates2('C2');
$drawing2->setOffsetX2($drawing->getImageWidth());  // what would setOffSetX do instead?
$drawing2->setOffsetY2($drawing->getImageHeight());  // what would setOffsetY do instead?

For getImageWidth/getImageHeight, this appears to be the raw image sizes, what about getting the scaled image sizes?

What features do you think are causing the issue

Which versions of PhpSpreadsheet and PHP are affected?

PhpSpreadsheet 1.24.1

oleibman commented 2 years ago

The distinction is between "one-cell anchor" (object moves with the anchor cell) and "two-cell anchor" (object will be moved and/or resized when the cells between the starting and ending anchors are moved or resized). So the two-cell anchor will resize with the cell, which is why it is legitimate for the start (setCoordinates) and end (setCoordinates2) coordinates to be the same. (Note that two-cell anchor can specify "one-cell" as an EditAs attribute, so may act like a one-cell anchor in that case.)

I created sample 48 as a playground for observing how the different anchor settings affect the behavior of the images. Note that there is also absolute positioning to consider. Play around with it to see if it answers your questions or raises new ones. Feel free to suggest (or, even better, submit as a PR) anything that would add clarity to the sample or the documentation. I do not know offhand the answers to a few of your questions (what would setOffsetX/Y do, how to get scaled size).

rolinger commented 2 years ago

I am taking notes on more than a handful of methods and how they work so I can add notes to the documentation. A lot of the documentation reads like a definition of a word where the word itself is used in the definition. I hope to provide some clarity where I can.