Unit Conversion

Utility class LengthUnitConverter can be used to convert values between various measurement units and the following example shows how you can use it.

Various Excel lengths extracted with GemBox.Spreadsheet for Java
Screenshot of various Excel lengths extracted with GemBox.Spreadsheet for Java
Upload your file (Drag file here)
import com.gembox.spreadsheet.*;

class Program {

    public static void main(String[] args) throws java.io.IOException {
        // If using Professional version, put your serial key below.

        ExcelFile workbook = ExcelFile.load("%InputFileName%");

        StringBuilder sb = new StringBuilder();

        ExcelWorksheet worksheet = workbook.getWorksheet(0);

        sb.append(String.format("Sheet left margin is: %1$s pixels.", Math.round(LengthUnitConverter.convert(worksheet.getPrintOptions().getLeftMargin(), LengthUnit.INCH, LengthUnit.PIXEL))));

        sb.append(String.format("Width of column A is: %1$s pixels.", Math.round(LengthUnitConverter.convert(worksheet.getColumn(0).getWidth(), LengthUnit.ZERO_CHARACTER_WIDTH_256_TH_PART, LengthUnit.PIXEL))));

        sb.append(String.format("Height of row 1 is: %1$s pixels.", Math.round(LengthUnitConverter.convert(worksheet.getRow(0).getHeight(), LengthUnit.TWIP, LengthUnit.PIXEL))));

        if (worksheet.getPictures().size() > 1) {
            ExcelPicture picture = worksheet.getPictures().get(1);
            sb.append(String.format("Image width x height is: %1$.2f centimeters x %2$.2f centimeters.",


Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.

Like it?

Download Buy

If you want to try the GemBox.Spreadsheet for Java yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.