Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Inline xfIndexes search in PHPExcel_Style::applyFromArray() #103

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

amironov
Copy link
Contributor

@amironov amironov commented Dec 3, 2012

Calculate hashes of styles for _cellXfCollection only once.

Use of cellXfExists() in applyFromArray() is bad idea. Every cloned new style in applyFromArray() is new object and will always be added to styles collection.

[Examples][cellXfExists]$ php 41applyFromArray.php
...
20:02:22 applyFromArray styles (begin)
20:02:22 _cellXfCollection count before: 1
20:02:22 _cellXfCollection count after size styles: 101
20:02:23 _cellXfCollection count after new style: 1101
20:02:23 applyFromArray styles (end), time: 0.42 s
20:02:23 Write to Excel2007 format
20:02:23 File written to 41applyFromArray.xlsx
20:02:23 Peak memory usage: 13.75 MB
...

[Examples][getCellXfByHashCode]$ php 41applyFromArray.php
...
20:02:37 applyFromArray styles (begin)
20:02:37 _cellXfCollection count before: 1
20:02:37 _cellXfCollection count after size styles: 10
20:02:37 _cellXfCollection count after new style: 11
20:02:37 applyFromArray styles (end), time: 0.19 s
20:02:37 Write to Excel2007 format
20:02:38 File written to 41applyFromArray.xlsx
20:02:38 Peak memory usage: 3.25 MB
...

[Examples][inline-search]$ php 41applyFromArray.php
...
20:03:02 applyFromArray styles (begin)
20:03:02 _cellXfCollection count before: 1
20:03:03 _cellXfCollection count after size styles: 10
20:03:03 _cellXfCollection count after new style: 11
20:03:03 applyFromArray styles (end), time: 0.14 s
20:03:03 Write to Excel2007 format
20:03:03 File written to 41applyFromArray.xlsx
20:03:03 Peak memory usage: 3.25 MB
...

@ssanders
Copy link

ssanders commented Feb 6, 2013

I tried this as applyFromArray() is so slow... but this is slow too. Hmm...

@amironov
Copy link
Contributor Author

What I must say? Don`t use applyFromArray(), try following code:

$style = new PHPExcel_Style;
$workbook->addCellXf($style);

foreach (...) {
    $cell = $worksheet->getCell(...);
    $cell->setValue(...);
    $cell->setXfIndex($style->getIndex());
}

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

Successfully merging this pull request may close these issues.

2 participants