How and where do I adjust cell width on this Excel export script?

Does anyone know how and where to adjust cell width on this script?   This script works awesome, I just need to widen the cells.   Thanks for your help!

// DB CONNECT INFO  HERE


    // This one makes the beginning of the xls file

    function xlsBOF() {

        echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);

        return;

    }



    // This one makes the end of the xls file

    function xlsEOF() {

        echo pack("ss", 0x0A, 0x00);

        return;

    }



    // this will write text in the cell you specify

    function xlsWriteLabel($Row, $Col, $Value ) {

        $L = strlen($Value);

        echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);

        echo $Value;

        return;

    }







    // make the connection an DB query

    $dbc = mysql_connect( $dbhost , $dbuser , $dbpass ) or die( mysql_error() );

    mysql_select_db( $dbname );

    //$q = "SELECT * FROM ".$dbtable." WHERE date ='$cdate'";

	$q = "SELECT * FROM ".$dbtable."";

    $qr = mysql_query( $q ) or die( mysql_error() );



    //start the object

     ob_start();



    // start the file

    xlsBOF();



    // these will be used for keeping things in order.

    $col = 0;

    $row = 0;



    // This tells us that we are on the first row

    $first = true;



    while( $qrow = mysql_fetch_assoc( $qr ) )

    {

        // Ok we are on the first row

        // lets make some headers of sorts

        if( $first )

        {

            foreach( $qrow as $k => $v )

            {

                // take the key and make label

                // make it uppper case and replace _ with ' '

                xlsWriteLabel( $row, $col, strtoupper( ereg_replace( "_" , " " , $k ) ) );

                $col++;

            }



            // prepare for the first real data row

            $col = 0;

            $row++;

            $first = false;

        }



        // go through the data

        foreach( $qrow as $k => $v )

        {



            // write it out

            xlsWriteLabel( $row, $col, $v );

            $col++;

        }



        // reset col and goto next row

        $col = 0;

        $row++;



    }



    xlsEOF();





	

	

    //write the contents of the object to a file

    file_put_contents($filename, ob_get_clean());

Open in new window

lawrence_devAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard DanekeTrainerCommented:
It looks like function xlsWriteLabel is where you write the cell.

In that function, you could add the column width parameter.   But, that function is not in the code you provided.  Would you want to set a fixed value for all columns or vary a fixed value for each column?

The code could be as simple as:

    Selection.ColumnWidth = 12  'to set column width of 12

Open in new window

0
lawrence_devAuthor Commented:
Thank You for your help!  Fixed width for all is fine for my application.   All of the fields are running together.
0
lawrence_devAuthor Commented:
Can anyone advise how to fix width universally on this script?

Thanks for your help!!
0
Richard DanekeTrainerCommented:
The code will work, but you did not provide the correct subroutine.

function xlsWriteLabel  is where you write the cell

If you want specific help where to place the width statement, provide the code for xlsWriteLabel.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.