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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:13:37+00:00 2026-06-14T05:13:37+00:00

I Use Spreadsheetgear to generate an Excel Workbook. My Workbook is very simple: I

  • 0

I Use Spreadsheetgear to generate an Excel Workbook.

My Workbook is very simple:

  • I insert Strings in cells
  • The first line is Bold
  • I draw borders around the headers and between the columns.

At the end of the process, i call myRange.Columns.AutoFit(), then I save the workbook.

When I open it with Excel, the autofit is almost good, but it still miss around 1.2 width units in each columns.

Is this a bug in AutoFit() implementation or am I missing something ?

  • 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-14T05:13:38+00:00Added an answer on June 14, 2026 at 5:13 am

    I actually asked SpreadsheetGear support about this as I was building my implementation about 6 months ago. I mentioned that b/c their AutoFit() was not fitting exactly right, that I was having to add a “fudge factor” to each column after autosizing.
    Support’s response was essentially that it was a known discrepancy with Excel, that they dont classify as a bug. Here’s what they had to say to me:

    The reason for auto-fit columns being slightly off between SpreadsheetGear and Excel is that the font metrics provided to us by .NET and GDI+ differ from those used in Excel. Because column dimensions are tied to fonts used in the workbook, and therefore font metrics, attempting to match Excel exactly just isn’t possible, unfortunately. We do our best to match Excel, but it is impossible to exactly match them in all cases.

    Interestingly, Excel’s actually quite inconsistent with their font metric calculations; try using SpreadsheetGear to create a workbook with long runs of text, perhaps adding 40-50 “a” characters to a cell. Now save that workbook to disk and open it in Excel 2007 or 2010 use their zoom slider in the lower-right-hand corner to zoom in and out at different points and note that the text shifts around relative to the column width quite a bit. SpreadsheetGear is much more consistent with this type of scenario.

    Regardless, your method of adding a little “fudge factor” to the column widths is the best workaround we can suggest. It is “hackish” but there’s simply nothing we can do to improve it since you’re dealing with two different environments and an inconsistent metrics in Excel itself.

    And here’s the “fudge factor” that I used to widen the columns as needed:

    ws.UsedRange.Columns.AutoFit()
    For col As Integer = 0 To ws.UsedRange.ColumnCount - 1
        ws.Cells(1, col).ColumnWidth *= 1.
    Next
    

    In C#

    ws.UsedRange.Columns.AutoFit()
    for (int col = 0; col < ws.UsedRange.ColumnCount; col++)
        ws.Cells[1, col].ColumnWidth *= 1.15;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use C#,want to upload excel file on google doc. bellow syntax use to upload
Use of gradient images is very common among developers for styling a page. Gradient
Use scenario is pretty simple: I have a desktop only application that could be
use strict; use warnings; open(FILE1, /cygdrive/c/cpros/mola.txt); my $line = <FILE1>; print $line; close(FILE1); open(FILE1,
use strict; use warnings; open(FILE1,/cygdrive/c/cpros/karthik/molk.txt); my $line = < FILE1 > ; print $line
use strict; use warnings; open(FILE4,cool.txt); open(FILE6,>./mool.txt); $line = <FILE4>; while ($line ne ) {
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
use level1\level2\level3; Can someone explain with a simple demo ?
use DBI(); What is causing this insert to fail to err 1, the SELECT
USE Database GO CREATE PROCEDURE FillTable @Id nvarchar(50), @ColumnNameArray nvarchar(4000), @ColumnValueArray nvarchar(4000) AS INSERT

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.