phpExcel getColumnDimension("A")->getWidth() always return -1

Topics: Developer Forum, Project Management Forum, User Forum
Jun 6, 2014 at 8:39 AM
Hi, I'm new in phpExcel and tring learn it. I have some problem with getting column width. In my possible tables there is a column with too high width. But it column may be change from file to file. so, I cann't hard code it's position. That is why I created a loop and trying to get width of each column. But method getWidth() from ColumnDimension.php always returns me -1; How can I solve this problem?
$colWidth = $objectSelectedWorksheet->getColumnDimension("$strCol")->getWidth();
where $objectSelectedWorksheet - is selected worksheet, $strCol - generated string name of column (i.e. A, B, etc).
Jun 6, 2014 at 9:24 AM
If you haven't defined a width for that column, then that's what you will get returned.... a value of -1 means "default", and the default is defined for the worksheet
$colWidth = $objectSelectedWorksheet->getDefaultColumnDimension()->getWidth();
If you've loaded this workbook from a file that contains a default value, then you can get it this way, otherwise if you get a -1 value again, then it's because your spreadsheet viewer is permitted to use whatever default it wants, and this may change from reader to reader or version to version
Jun 6, 2014 at 10:16 AM
Here what I have in excel. you see, that I put a lot of text in first cell A1. the width of column('A') is not high.
Here what I get in html. First column has width too high. What can I do to set width shorter? But pay attention, the column may change from file to file.
Is it possible to correct it? or I have obly to correct this trouble in ms excel and load to php with correct widths?
Thanks in advance