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

Can't write in an existing xls file: Cell coordinate can not be zero-length string #2229

Closed
ClCfe opened this issue Jul 20, 2021 · 3 comments

Comments

@ClCfe
Copy link

ClCfe commented Jul 20, 2021

Hello,

This is:

a bug report

What is the expected behavior?

I am using PhpSpreadsheet 1.18.0

I need to read a xlsx file and add some information and then write it

What is the current behavior?

PhpOffice\PhpSpreadsheet\Exception
In file: PhpSpreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php
line: 39
message: Cell coordinate can not be zero-length string

Trace:
#0 PhpSpreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(124): PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateFromString('')
#1 PhpSpreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(101): PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteCoordinate('')
#2 PhpSpreadsheet/src/PhpSpreadsheet/Writer/Xlsx/DefinedNames.php(169): PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteReference('')
#3 PhpSpreadsheet/src/PhpSpreadsheet/Writer/Xlsx/DefinedNames.php(45): PhpOffice\PhpSpreadsheet\Writer\Xlsx\DefinedNames->writeNamedRangeForPrintArea(Object(PhpOffice\PhpSpreadsheet\Worksheet\Worksheet), 1)
#4 PhpSpreadsheet/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php(56): PhpOffice\PhpSpreadsheet\Writer\Xlsx\DefinedNames->write()
#5 PhpSpreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php(372): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook->writeWorkbook(Object(PhpOffice\PhpSpreadsheet\Spreadsheet), true)
#6 example.php(12): PhpOffice\PhpSpreadsheet\Writer\Xlsx->save('/tmp/test_out.xlsx')

What are the steps to reproduce?

<?php

require __DIR__ . '/vendor/autoload.php';

$file_in='/tmp/test_in.xlsx';
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($file_in);

//call xlsx writer without any modification

$file_out='/tmp/test_out.xlsx';
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($file_out);

Which versions of PhpSpreadsheet and PHP are affected?

php 7.4 and PhpSpreadsheet 1.18.0

I would prefer to send test_in.xlsx file privately

@stSaHiB
Copy link

stSaHiB commented Jan 7, 2022

same problem here when opening a file and saving it, using 1.21.0.
Worked with old Versions (~8.12)

It seems like the printareas arent read from the source file, if they are defined in there.
Quickfix to prevent the error occurring: open source file in excel and set print scaling in page setup to 100% (or just remove the print area).

Or if you need scaling, set the printarea by hand:
$sheets['main']->getPageSetup()->setPrintArea("{$col_min}1:{$col_max}{$row_count}");

@oleibman
Copy link
Collaborator

oleibman commented Jan 7, 2022

I created a spreadsheet with a print area, and read it and created a copy using the code above. No problem. To investigate further, I will need to see an example of a spreadsheet that demonstrates this problem.

@oleibman
Copy link
Collaborator

No update in 6 months. No file to demonstrate problem. Closing.

MarkBaker added a commit that referenced this issue Sep 25, 2022
### Added

- Implementation of the new `TEXTBEFORE()`, `TEXTAFTER()` and `TEXTSPLIT()` Excel Functions
- Implementation of the `ARRAYTOTEXT()` and `VALUETOTEXT()` Excel Functions
- Support for [mitoteam/jpgraph](https://packagist.org/packages/mitoteam/jpgraph) implementation of
  JpGraph library to render charts added.
- Charts: Add Gradients, Transparency, Hidden Axes, Rounded Corners, Trendlines, Date Axes.

### Changed

- Allow variant behaviour when merging cells [Issue #3065](#3065)
  - Merge methods now allow an additional `$behaviour` argument. Permitted values are:
    - Worksheet::MERGE_CELL_CONTENT_EMPTY - Empty the content of the hidden cells (the default behaviour)
    - Worksheet::MERGE_CELL_CONTENT_HIDE - Keep the content of the hidden cells
    - Worksheet::MERGE_CELL_CONTENT_MERGE - Move the content of the hidden cells into the first cell

### Deprecated

- Axis getLineProperty deprecated in favor of getLineColorProperty.
- Moved majorGridlines and minorGridlines from Chart to Axis. Setting either in Chart constructor or through Chart methods, or getting either using Chart methods is deprecated.
- Chart::EXCEL_COLOR_TYPE_* copied from Properties to ChartColor; use in Properties is deprecated.
- ChartColor::EXCEL_COLOR_TYPE_ARGB deprecated in favor of EXCEL_COLOR_TYPE_RGB ("A" component was never allowed).
- Misspelled Properties::LINE_STYLE_DASH_SQUERE_DOT deprecated in favor of LINE_STYLE_DASH_SQUARE_DOT.
- Clone not permitted for Spreadsheet. Spreadsheet->copy() can be used instead.

### Removed

- Nothing

### Fixed

- Fix update to defined names when inserting/deleting rows/columns [Issue #3076](#3076) [PR #3077](#3077)
- Fix DataValidation sqRef when inserting/deleting rows/columns [Issue #3056](#3056) [PR #3074](#3074)
- Named ranges not usable as anchors in OFFSET function [Issue #3013](#3013)
- Fully flatten an array [Issue #2955](#2955) [PR #2956](#2956)
- cellExists() and getCell() methods should support UTF-8 named cells [Issue #2987](#2987) [PR #2988](#2988)
- Spreadsheet copy fixed, clone disabled. [PR #2951](#2951)
- Fix PDF problems with text rotation and paper size. [Issue #1747](#1747) [Issue #1713](#1713) [PR #2960](#2960)
- Limited support for chart titles as formulas [Issue #2965](#2965) [Issue #749](#749) [PR #2971](#2971)
- Add Gradients, Transparency, and Hidden Axes to Chart [Issue #2257](#2257) [Issue #2229](#2929) [Issue #2935](#2935) [PR #2950](#2950)
- Chart Support for Rounded Corners and Trendlines [Issue #2968](#2968) [Issue #2815](#2815) [PR #2976](#2976)
- Add setName Method for Chart [Issue #2991](#2991) [PR #3001](#3001)
- Eliminate partial dependency on php-intl in StringHelper [Issue #2982](#2982) [PR #2994](#2994)
- Minor changes for Pdf [Issue #2999](#2999) [PR #3002](#3002) [PR #3006](#3006)
- Html/Pdf Do net set background color for cells using (default) nofill [PR #3016](#3016)
- Add support for Date Axis to Chart [Issue #2967](#2967) [PR #3018](#3018)
- Reconcile Differences Between Css and Excel for Cell Alignment [PR #3048](#3048)
- R1C1 Format Internationalization and Better Support for Relative Offsets [Issue #1704](#1704) [PR #3052](#3052)
- Minor Fix for Percentage Formatting [Issue #1929](#1929) [PR #3053](#3053)
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