Autosizing over columns in a worksheet

Topics: Developer Forum, User Forum
Apr 4, 2010 at 6:42 AM

What is the canonical way to iterate over every column in your worksheet, autosizing each column? In my case, the number of columns will vary. I tried this, and it didn't work:

 

 

        $docHighCol = $xlsDoc->getActiveSheet()->getHighestColumn();
        for ($col='A'; $col <= $docHighCol; $col++){
            $xlsDoc->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
        }

The first problem is that getHighestColumn didn't return a string; it returned an integer (19). I converted it appropriately by using this:

 

        $docHighCol += ord('A');
        $docHighCol = chr($docHighCol);

I'm not sure if this is a bug or not since getHighestColumn is shown, in the documentation, to return a string value.

 

 

Using: PHPExcel 1.7.2, MacOSX 10.5.8, PHP 5.2.11

 

 

  Using: PHPExcel 1.7.2, MacOSX 10.5.8, PHP 5.2.11
      $docHighCol = $xlsDoc->getActiveSheet()->getHighestColumn();
        for ($col='A'; $col <= $docHighCol; $col++){
            $xlsDoc->getActiveSheet()->getColumnDimension($col)->setAutoSize(true);
        }

 

Developer
Apr 5, 2010 at 9:47 AM

Are you really sure that getHighestColumn() returns an integer? It is not supposed to.

Can you upload an example? You can upload here:

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10749

Jun 22, 2010 at 6:33 PM
I'm having problems reaching phpexcel.codeplex right now. But yes, I'm sure it is returning an integer. Here's some sample code (I've attached it).

Avery



On Mon, Apr 5, 2010 at 4:47 PM, koyama <notifications@codeplex.com> wrote:

From: koyama

Are you really sure that getHighestColumn() returns an integer? It is not supposed to.

Can you upload an example? You can upload here:

http://phpexcel.codeplex.com/WorkItem/View.aspx?WorkItemId=10749

Read the full discussion online.

To add a post to this discussion, reply to this email (PHPExcel@discussions.codeplex.com)

To start a new discussion for this project, email PHPExcel@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com


Jun 22, 2010 at 6:47 PM
I uploaded the example here: http://phpexcel.codeplex.com/Project/Download/AttachmentDownload.ashx?ProjectName=PHPExcel&WorkItemId=10749&FileAttachmentId=4593
Jun 22, 2010 at 7:35 PM
This problem doesn't appear in 1.7.3c (which I just downloaded), except there's a huge regression in writing the file to disk. This is on MacOSX 10.5.8. We can close this one but I might file another bug...