-1

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:

2
  • How are you converting the xlsx file to Google Sheets format?
    – Rubén
    Jan 11, 2021 at 17:05
  • @Rubén uploading it to drive or even just viewing the xlsx file via an android device.
    – HTMHell
    Jan 11, 2021 at 23:06

1 Answer 1

0

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.

2
  • One thing I don't understand is why is it getting converted wrong? If they use a different unit of measure when they convert the xlsx file, shoulldn't it still be the correct size?
    – HTMHell
    Jan 11, 2021 at 23:15
  • @HTMHell That is something that only Google can answer.
    – Rubén
    Feb 10, 2021 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.