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
Various Excel lengths extracted with GemBox.Spreadsheet
Upload your file (Drag file here)
using System;
using System.Text;
using GemBox.Spreadsheet;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var workbook = ExcelFile.Load("%InputFileName%");

        var sb = new StringBuilder();

        var worksheet = workbook.Worksheets[0];

        sb.AppendFormat("Sheet left margin is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.PrintOptions.LeftMargin, LengthUnit.Inch, LengthUnit.Pixel)));
        sb.AppendLine();

        sb.AppendFormat("Width of column A is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.Columns[0].Width, LengthUnit.ZeroCharacterWidth256thPart, LengthUnit.Pixel)));
        sb.AppendLine();

        sb.AppendFormat("Height of row 1 is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.Rows[0].Height, LengthUnit.Twip, LengthUnit.Pixel)));
        sb.AppendLine();

        var picture = worksheet.Pictures[1];
        sb.AppendFormat("Image width x height is: {0} centimeters x {1} centimeters.",
            Math.Round(picture.Position.GetWidth(LengthUnit.Centimeter), 2),
            Math.Round(picture.Position.GetHeight(LengthUnit.Centimeter), 2));

        Console.WriteLine(sb.ToString());
    }
}
Imports System
Imports System.Text
Imports GemBox.Spreadsheet

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")

        Dim workbook = ExcelFile.Load("%InputFileName%")

        Dim sb = New StringBuilder()

        Dim worksheet = workbook.Worksheets(0)

        sb.AppendFormat("Sheet left margin is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.PrintOptions.LeftMargin, LengthUnit.Inch, LengthUnit.Pixel)))
        sb.AppendLine()

        sb.AppendFormat("Width of column A is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.Columns(0).Width, LengthUnit.ZeroCharacterWidth256thPart, LengthUnit.Pixel)))
        sb.AppendLine()

        sb.AppendFormat("Height of row 1 is: {0} pixels.", Math.Round(LengthUnitConverter.Convert(worksheet.Rows(0).Height, LengthUnit.Twip, LengthUnit.Pixel)))
        sb.AppendLine()

        Dim picture = worksheet.Pictures(1)
        sb.AppendFormat("Image width x height is: {0} centimeters x {1} centimeters.",
            Math.Round(picture.Position.GetWidth(LengthUnit.Centimeter), 2),
            Math.Round(picture.Position.GetHeight(LengthUnit.Centimeter), 2))

        Console.WriteLine(sb.ToString())
    End Sub
End Module

Check next example or download examples from GitHub.