[SOLVED] About column widths...

Topics: User Forum
Jun 23, 2010 at 5:32 PM
Edited Jun 23, 2010 at 5:57 PM
From the documentation (Page 27):

[quote]
If you have some Excel file and need to know the column widths in measure 3), you can read the Excel file with PHPExcel and echo the retrieved values.
[/quote]

But there is no example showing how....
Jul 5, 2010 at 9:50 PM
ANYBODY???!?!?!?!!
Jul 6, 2010 at 6:51 AM

Can you try with the following code?

$objPHPExcel->getActiveSheet()->getColumnDimension('D')->getWidth();
All the best.

Jul 6, 2010 at 1:32 PM
How do I loop the columns between A and M?
Jul 6, 2010 at 8:29 PM

Thanks for the tip.

Mar 1, 2011 at 8:12 PM
Edited Mar 1, 2011 at 8:18 PM

Hi. I have tried the above code w/1.7.6 reading a client's XLSX with all columns set to width 20 in Excel, but the value returned is -1..?

I have also tried this code...

$workbook->getActiveSheet()->getDefaultColumnDimension()->getWidth();

...and the value returned is 10..? When I write an XLSX with this code...

$workbook->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);

...the value Excel sees is 19.29...

It would help to either

  • ship PHPExcel with a test file that correctly reads and echoes column widths in the format PHPExcel wants from an inputted file
  • some function that auto-converts an inputted Excel width (like 20)

I am migrating from Spreadsheet_Excel_Writer which I think PHPExcel uses too but don't recall this issue with it..?

I guess adding .71 to setWidth() mostly works though.