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

Update SimpleXLSXGen.php #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

xaviermdq
Copy link
Contributor

Minor changes:

  1. Method with no interaction with object properties/methods, converted to static method: num2name (used in _sheetToXML).
  2. Constructor: It's not necessary to initialize the $sheets property since, in the addSheet method, the index 0 of $sheets is overwritten ($curSheet initialized at -1 and becomes 0 when addSheet is called).
  3. Minor XML formatting changed (newlines and light indentation): in $template definition (constructor), $SHEETVIEWS, $ROWS, $COLS, $AUTOFILTER, $HYPERLINKS (_sheetToXML), etc.
  4. addSheet method: $rows initialization changed to support associative arrays. In the original addSheet method, it is checked if $row is a 2-dimensional array but considering $row as a classic array (2-dimensional array with consecutive numeric indices). But traversing data from the array (in the _sheetToXML method) is done with foreach, which allows the use of arbitrary indexes. So, I think a more correct way to check $row presence is to use:
if (is_array($rows) && is_array($rows[array_key_first($rows)]))

but it needs PHP 7.3 so we can use:

if (is_array($rows)) {
	foreach ($rows as $row) {
		if (is_array($row)) $this->sheets[$this->curSheet]['rows'] = $rows;
		break;
	}
}
  1. saveAs and downloadAs methods: change filename correction to a more aggressive aproach so can be saved in *nix/Win filesystems. Both methods return false on failure or used filename on success.
  2. _write method: search & replace sentences changed to one multi-line sentence (I think it gives better readability).
  3. Changed coord2cell/cell2coord methods to use array for sheet coordinates. This caused a change in the _sheetToXML method where these methods are used to calculate frozen cells.
  4. Method _sheetToXML: added empty element at the end of the arrays $ROWS, $COLS, $MERGECELLS, $HYPERLINKS (like it was originally with $MERGECELLS) and deleted the new lines in the sheet template.
  5. The documented methods (and class), converted to PHPDoc format.
  6. date2excel method: $century vriable used to calculate $decade to avoid repeating calculation.

I have removed the code related to comments in cells to make it easier to see the changes. In a later version, I will add comment support.
Also, and for the same reason, I did not change the order of the methods but it would be nice to group the static methods, the setters and the rest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant