'Google Sheets - Pixel Width of a text
In Google Sheets, is there a way to calculate the width, in pixels, of a piece of text given a font and a font size? Excel has a PixelWidth function, but I didn't find any equivalent function or script for Sheets.
My goal is to be able to compare lengths of translated sentences in a UI. For example, if the English sentence is "Hi", and the French translation is "Bonjour", I would like to calculate how much more space the translation will be using. The length of the string is not enough since fonts have different character widths. I would like to calculate it directly in Sheets to give translators an indication of if the sentence can fit in the UI element.
Solution 1:[1]
Technically, Not possible for a rule of thumb when it comes to pixel width measurement of text.
I had been working on this problem and learned this is impossible because Pixel widths are different depending on the screen resolution. The higher the resolution, the more pixels there are.
Example: A High Definition TV with 1080p resolution is composed of two million pixels (1920 x 1080), while a 4K TV (aka Ultra High Definition) has over eight million pixels (3840 x 2160)(source).
So there would be no uniform pixel width measurement to go by in general. So I defaulted to using an average pixel width from 4 sites that measure for SERPs and then continue to iterate the value lengths as we launch websites using the pixel counter to try to avoid truncated search results.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Daine Dvorak |