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 the 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.",


See also

Next steps

GemBox.Spreadsheet for Java is a component that enables you to read, write, edit and convert spreadsheet files from your applications using one simple API.

Download Buy