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

/Writer/Ods/Content.php | unhelpful "throw new Exception" because of unfinished developement #1674

Closed
schultz-it-solutions opened this issue Oct 9, 2020 · 3 comments

Comments

@schultz-it-solutions
Copy link

schultz-it-solutions commented Oct 9, 2020

bug report

in PhpOffice/PhpSpreadsheet/Writer/Ods/Content.php there are two "Exceptions" thrown, when the datatype of the cell is either "TYPE_ERROR" or "TYPE_INLINE", because the relevant code is not yet developed.
Throwing an exception breaks the creation-process for such a document, which is not helpful. It would probably be more suitable not to "crash" the program.

What is the expected behavior?

Either develop the nessessary functionality, or as an intermediate solution, modify the content of such a cell with an error message.
In my current case, the cell values are actually "NULL". The Xlsx writer translates this to "#NV", and the Ods writer should act accordingly.

What is the current behavior?

Program throws an exception and stops processing, loosing ALL data, rather than only the unprocessable cell.

What are the steps to reproduce?

Provide input-data with actual NULL values, and then use PhpSpreadsheet writers Xlsx and Ods respectively.

To circumvent the actual issue, I out-commented the "throw exception" and write the exception-message into the cell value:

            switch ($cell->getDataType()) {
                case DataType::TYPE_BOOL:
                    $objWriter->writeAttribute('office:value-type', 'boolean');
                    $objWriter->writeAttribute('office:value', $cell->getValue());
                    $objWriter->writeElement('text:p', $cell->getValue());

                    break;
                case DataType::TYPE_ERROR:
/*SITS*/          //throw new Exception('Writing of error not implemented yet.');
                    $objWriter->writeAttribute('office:value-type', 'string');
                    $objWriter->writeElement('text:p', 'Writing of error not implemented yet.');

                    break;
                case DataType::TYPE_FORMULA:
                    $formulaValue = $cell->getValue();
                    if ($this->getParentWriter()->getPreCalculateFormulas()) {
                        try {
                            $formulaValue = $cell->getCalculatedValue();
                        } catch (Exception $e) {
                            // don't do anything
                        }
                    }
                    $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue());
                    if (is_numeric($formulaValue)) {
                        $objWriter->writeAttribute('office:value-type', 'float');
                    } else {
                        $objWriter->writeAttribute('office:value-type', 'string');
                    }
                    $objWriter->writeAttribute('office:value', $formulaValue);
                    $objWriter->writeElement('text:p', $formulaValue);

                    break;
                case DataType::TYPE_INLINE:
/*SITS*/            //throw new Exception('Writing of inline not implemented yet.');
                    $objWriter->writeAttribute('office:value-type', 'string');
                    $objWriter->writeElement('text:p', 'Writing of inline not implemented yet.');

                    break;
                case DataType::TYPE_NUMERIC:
                    $objWriter->writeAttribute('office:value-type', 'float');
                    $objWriter->writeAttribute('office:value', $cell->getValue());
                    $objWriter->writeElement('text:p', $cell->getValue());

                    break;
                case DataType::TYPE_STRING:
                    $objWriter->writeAttribute('office:value-type', 'string');
                    $objWriter->writeElement('text:p', $cell->getValue());

                    break;
            }
@stale
Copy link

stale bot commented Dec 25, 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 Dec 25, 2020
@Progi1984
Copy link
Member

@schultz-it-solutions I think this issue has been fixed in last versions of PhpSpreadsheet.

@stale stale bot removed the stale label Aug 29, 2023
@oleibman
Copy link
Collaborator

oleibman commented Sep 1, 2023

@Progi1984 is correct. This was fixed with PR #1688, implemented in Jan. 2021, and part of the official release since 1.17.0 (current is 1.29).

@oleibman oleibman closed this as completed Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants