Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7734055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:09:16+00:00 2026-06-01T07:09:16+00:00

I want to make sure that no value is cut off in a workbook

  • 0

I want to make sure that no value is cut off in a workbook produced by phpExcel. To do this I call

  $oCurrentSheet->getColumnDimension($aCurrentCoords['x'])->setAutoSize(true);

every time I write a cell.
This doesn’t seem to work: Many columns end up really tiny.

Does anybody know how to make sure every column in the outputted excel workbook is sized according to its content?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:09:19+00:00Added an answer on June 1, 2026 at 7:09 am

    Don’t do this every time you write a cell… it’s an unnecessary overhead. Do it just once for each column.

    Be warned, it’s still expensive when saving, because PHPExcel then walks through each cell in that column working out the width necessary based on the content of that cell, taking into account formula calculation and formatting, and using the maximum size of any cell in that column. Even then it isn’t a perfect solution: the default behaviour is to estimate, counting the number of characters to display, and using a generic multiplier based on font (Arial, Verdana of Calibri) and a little bit of padding. For a more accurate calculation, you can change the method used for the calculation, and the code then uses GD to build a ttf bounding box and base the cell size on the dimensions of that box. This is a more accurate calculation, but a lot slower.

    You can change the calculation method using:

    PHPExcel_Shared_Font::setAutoSizeMethod($method);
    

    before saving, where $method is one of the following:

    PHPExcel_Shared_Font::AUTOSIZE_METHOD_APPROX
    PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT
    

    This still isn’t a perfect solution, but it’s the best calculation that PHPExcel can do.

    An alternative is to call the worksheet’s calculateColumnWidths() method yourself directly before saving… and then walk through each column’s dimension increasing the value by perhaps 5% to try and ensure that the entire column fits, before saving.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my ajax pager code below: Now I want to make sure that
I want to make sure that if any error occurs during the database processing
I want to make sure that all 3 conditions result in the same answer
I want to make sure that I only print maximum 80 character long lines,
I am using APEX 3.2 and I want to make sure that a text
I have the following code; I want to make sure that submit does not
Many of my views fetch external resources. I want to make sure that under
To allow caching a PHP generated file, I want to make sure, that the
I want to create a method like example below to make sure that a
I am making an application in which i want to make sure that only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.