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 9013527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:17:27+00:00 2026-06-16T03:17:27+00:00

Hi. I’m using xlwt package with Python to make an application that writes to

  • 0

Hi. I’m using xlwt package with Python to make an application that writes to excel files.

I have a function that returns the desired width of a cell so i can make the cell big enough to fit the text. However, my function breaks down when i’m writing text that’s in uppercase, as it then returns a width that is far smaller than the actual text.

I don’t know what’s the problem. Any advice would be much appreciated.

def getWidth(self, num_characters):
    """ Returns the approximate width of a cell. """
    return int((1+num_characters) * 256)
  • 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-16T03:17:28+00:00Added an answer on June 16, 2026 at 3:17 am

    All you’re doing with the getWidth function is guessing how much space you’re going to need. The reason you’re guessing is because each letter takes a different amount of space (“iiiii” takes up less room than “mmmmm”). Obviously, capital letters will take up more space.

    There are two simple (but not perfect) fixes to this problem:

    1. Increase the width per character for all cells. This would mean modifying the value 256 in your function. I would say increasing it by 50% would probably fix your problem.
    2. Make everything that you’re inserting into the cells lowercase before insertion.

    The code for option 1 would be pretty similar to what you have already:

    def getWidth(self, num_characters):
        """ Returns the approximate width of a cell. """
        return int((1+num_characters) * 384)
    

    The code for option 2 would involve calling the lower method on your string before inserting. It would look something like this:

    my_cell_value = "THIS IS ALL CAPS!"
    my_worksheet.write(1,1,my_cell_value.lower())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.