Skip to content

Commit ddc7e59

Browse files
UG documentation 978280: FAQ for how to get the column width and row height in pixels
1 parent 2abc3b5 commit ddc7e59

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: How to get the column width and row height in pixels | Syncfusion
3+
description: Code example showing how to retrieve column width and row height in pixels using the Syncfusion .NET Excel library (XlsIO).
4+
platform: document-processing
5+
control: XlsIO
6+
documentation: UG
7+
---
8+
9+
# How to get the column width and row height in pixels?
10+
11+
In Essential® XlsIO, you can obtain column widths and row heights in pixels by using the [GetColumnWidthInPixels](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_GetColumnWidthInPixels_System_Int32_) and [GetRowHeightInPixels](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorksheet.html#Syncfusion_XlsIO_IWorksheet_GetRowHeightInPixels_System_Int32_) methods. The below code snippet demonstrates this.
12+
13+
{% tabs %}
14+
{% highlight c# tabtitle="C# [Cross-platform]" %}
15+
using (ExcelEngine excelEngine = new ExcelEngine())
16+
{
17+
IApplication application = excelEngine.Excel;
18+
application.DefaultVersion = ExcelVersion.Xlsx;
19+
FileStream inputStream = new FileStream("InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
20+
IWorkbook workbook = application.Workbooks.Open(inputStream);
21+
IWorksheet worksheet = workbook.Worksheets[0];
22+
23+
var range = worksheet.UsedRange["A1"];
24+
25+
//Get the Column width in pixels
26+
var width = worksheet.GetColumnWidthInPixels(range.Column);
27+
28+
//Get the Row height in pixels
29+
var height = worksheet.GetRowHeightInPixels(range.Row);
30+
31+
#region Save
32+
//Saving the workbook
33+
FileStream outputStream = new FileStream("RowsandColumns.xlsx", FileMode.Create, FileAccess.Write);
34+
workbook.SaveAs(outputStream);
35+
#endregion
36+
37+
//Dispose streams
38+
outputStream.Dispose();
39+
inputStream.Dispose();
40+
}
41+
{% endhighlight %}
42+
43+
{% highlight c# tabtitle="C# [Windows-specific]" %}
44+
using (ExcelEngine excelEngine = new ExcelEngine())
45+
{
46+
IApplication application = excelEngine.Excel;
47+
application.DefaultVersion = ExcelVersion.Xlsx;
48+
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
49+
IWorksheet worksheet = workbook.Worksheets[0];
50+
var range = worksheet.UsedRange["A1"];
51+
52+
//Get the Column width in pixels
53+
var width = worksheet.GetColumnWidthInPixels(range.Column);
54+
55+
//Get the Row height in pixels
56+
var height = worksheet.GetRowHeightInPixels(range.Row);
57+
58+
workbook.SaveAs("RowsandColumns.xlsx");
59+
}
60+
{% endhighlight %}
61+
62+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
63+
Using excelEngine As ExcelEngine = New ExcelEngine()
64+
Dim application As IApplication = excelEngine.Excel
65+
application.DefaultVersion = ExcelVersion.Excel2013
66+
Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx", ExcelOpenType.Automatic)
67+
Dim worksheet As IWorksheet = workbook.Worksheets(0)
68+
69+
Dim range = worksheet.UsedRange("A1")
70+
' Column width in pixels
71+
Dim width As Integer = worksheet.GetColumnWidthInPixels(range.Column)
72+
' Row height in pixels
73+
Dim height As Integer = worksheet.GetRowHeightInPixels(range.Row)
74+
75+
workbook.SaveAs("GridLineColor.xlsx")
76+
End Using
77+
{% endhighlight %}
78+
{% endtabs %}
79+
80+
## See Also
81+
82+
* [How to format text within a cell?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-format-text-within-a-cell)
83+
* [How to unfreeze the rows and columns in XlsIO?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-unfreeze-the-rows-and-columns-in-xlsio)
84+
* [What is the maximum range of Rows and Columns?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/what-is-the-maximum-range-of-rows-and-columns)
85+
* [How to find values with a matching case for specific column in Excel?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-find-values-with-a-matching-case-for-specific-column-in-excel)
86+
* [How to protect certain cells in a worksheet?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-protect-certain-cells-in-a-worksheet)
87+
* [How to search a value in only specific columns of an Excel worksheet?](https://help.syncfusion.com/document-processing/excel/excel-library/net/faqs/how-to-search-a-value-in-only-specific-columns-of-an-excel-worksheet)

0 commit comments

Comments
 (0)