Google-sheets – How tell Google Sheets to not change columns width

google sheetsmicrosoft excel

I wrote a script that generates excel files. In those files, I add images inside cells. I set the width of the images cell by calculating the total images width.

Here is how it looks in MS Excel:

enter image description here

And here's how it looks in Google Sheets (same file):
enter image description here

As you can see, the width of the cell is smaller than the image in Google Docs, but in MS Excel it's the correct size.

Looking at she sheet1.xml of the original file, I can see:

<cols>
    <col min="1" max="1" width="10" customWidth="1"/>
    <col min="2" max="2" width="10" customWidth="1"/>
    <col min="3" max="3" width="12.1" customWidth="1"/>
    <col min="4" max="4" width="20.050541516245488" customWidth="1"/>
    <col min="5" max="5" width="10" customWidth="1"/>
    <col min="6" max="6" width="14.3" customWidth="1"/>
</cols>

And in the new file (after uploading to google, I downloaded it as xlsx) I see:

<cols>
    <col customWidth="1" min="1" max="2" width="7.78"/>
    <col customWidth="1" min="3" max="3" width="9.44"/>
    <col customWidth="1" min="4" max="4" width="15.56"/>
    <col customWidth="1" min="5" max="5" width="7.78"/>
    <col customWidth="1" min="6" max="6" width="11.11"/>
    <col customWidth="1" min="7" max="26" width="8.33"/>
</cols>

Google changed the column sizes. Why, and how can I solve this?

Links:

Best Answer

It's not possible.

The above is because

  1. Google Sheets and Microsoft Excel use different unit of measure to set the cell dimensions. See Is there a column width bug in Google sheets?
  2. There are some known issues i.e. 1) Sheet.getRowHeight() and Sheet.getColumnWidth() report wrong sizes 2) Google Apps Script Sheets getRowHeight() only returns the correct height when a row height is specified, does not work with Text wrap. that might be related
  3. There is no way for end-users to change the way that Google convert Excel files to Google Sheets format

One workaround is to make another script that replicates what is done by the script that you use to creates the Excel but to create the Google Sheets spreadsheet.

Another workaround might be to use Google Apps Script to adjust the columns sizes.