-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Force formula re-calculation on file open from Excel needs a new attribute when writing to xlsx #456
Comments
Yes found this problem too with excel 2016 on windows 10. This fix def needs to make it in. Here is the custom writer I used to work around... use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as DefaultXlsx;
class Xlsx extends DefaultXlsx
{
public function __construct(Spreadsheet $spreadsheet)
{
parent::__construct($spreadsheet);
//replace private writer part with our writer
$refl = new \ReflectionClass(DefaultXlsx::class);
$prop = $refl->getProperty('writerParts');
$prop->setAccessible(true);
$writers = $prop->getValue($this);
$writers['workbook'] = new class($this) extends Workbook {
public function writeWorkbook(Spreadsheet $spreadsheet, $recalcRequired = false) {
$xml = parent::writeWorkbook($spreadsheet, $recalcRequired);
return substr_replace($xml, ' forceFullCalc="1" ', stripos($xml, 'calcId="'), 0);
}
};
$prop->setValue($this,$writers);
}
} |
Could you maybe provide a PR that fixes this? |
Ok, will try it in the next few days, thanks for the feedback 👍 |
5 tasks
Created PR #515 related to this issue. |
billblume
pushed a commit
to billblume/PhpSpreadsheet
that referenced
this issue
Jun 12, 2018
Dfred
pushed a commit
to Dfred/PhpSpreadsheet
that referenced
this issue
Nov 20, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is:
What is the expected behavior?
Xlsx files written using this library should have its formulas recalculated when opening the file from Excel.
What is the current behavior?
The formulas do not get recalculated.
What are the steps to reproduce?
I have seen that the library will set these attributes on the generated
xl/workbook.xml
inside the xslx compressed file:<x:calcPr calcId="999999" calcMode="auto" fullCalcOnLoad="1" calcCompleted="0"/>
BUT if I tamper the file with C# library OpenXML and follow the steps from the accepted answer from the post, which suggests doing this:
Then the generated
xl/workbook.xml
file has following flags instead:<x:calcPr calcId="999999" calcMode="auto" fullCalcOnLoad="1" calcCompleted="0" forceFullCalc="1" />
Notice the additional
forceFullCalc="1"
attribute.If I modify the file src/PhpSpreadsheet/Writer/Xlsx/Workbook.php and change this...
... to this (changes in bold)...
Everything works as expected.
Which versions of PhpSpreadsheet and PHP are affected?
The latset version of PhpSpreadsheet
The text was updated successfully, but these errors were encountered: