Unit Conversion

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

Screenshot of various Excel lengths extracted with GemBox.Spreadsheet for Java
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.
        SpreadsheetInfo.setLicense("FREE-LIMITED-KEY");

        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('\n');

        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('\n');

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

        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.",
                    picture.getPosition().getWidth(LengthUnit.CENTIMETER),
                    picture.getPosition().getHeight(LengthUnit.CENTIMETER)));
        }

        System.out.println(sb.toString());
    }
}

Check next example or download examples from GitHub.