|
| 1 | +--- |
| 2 | +title: Get maximum rows and columns in a worksheet | Syncfusion |
| 3 | +description: Code example to get the maximum number of rows and columns supported in an Excel worksheet using Syncfusion .NET Excel library (XlsIO). |
| 4 | +platform: document-processing |
| 5 | +control: XlsIO |
| 6 | +documentation: UG |
| 7 | +--- |
| 8 | + |
| 9 | +# How to get the maximum rows and columns in a worksheet using XlsIO? |
| 10 | + |
| 11 | +The [MaxRowCount](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorkbook.html#Syncfusion_XlsIO_IWorkbook_MaxRowCount) and [MaxColumnCount](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorkbook.html#Syncfusion_XlsIO_IWorkbook_MaxColumnCount) properties of [IWorkbook](https://help.syncfusion.com/cr/document-processing/Syncfusion.XlsIO.IWorkbook.html) return the maximum number of rows and columns supported in an Excel worksheet. |
| 12 | + |
| 13 | +The following code examples demonstrate how to retrieve the maximum number of rows and columns supported in an Excel worksheet using C# (cross-platform and Windows-specific) and VB.NET. |
| 14 | + |
| 15 | +{% tabs %} |
| 16 | +{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Maximum%20number%20of%20rows%20and%20columns%20supported/.NET/MaximumNumberOfRowsColumns/MaximumNumberOfRowsColumns/Program.cs,180" %} |
| 17 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 18 | +{ |
| 19 | + IApplication application = excelEngine.Excel; |
| 20 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 21 | + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); |
| 22 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 23 | + |
| 24 | + // To get the maximum supported rows and columns |
| 25 | + int maxRow = workbook.MaxRowCount; |
| 26 | + int maxColumns = workbook.MaxColumnCount; |
| 27 | + |
| 28 | + // Display the maximum number of rows and columns supported |
| 29 | + Console.WriteLine("Maximum number of rows supported: " + maxRow.ToString()); |
| 30 | + Console.WriteLine("Maximum number of columns supported: " + maxColumns.ToString()); |
| 31 | +} |
| 32 | +{% endhighlight %} |
| 33 | + |
| 34 | +{% highlight c# tabtitle="C# [Windows-specific]" %} |
| 35 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 36 | +{ |
| 37 | + IApplication application = excelEngine.Excel; |
| 38 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 39 | + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/Input.xlsx")); |
| 40 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 41 | + |
| 42 | + // To get the maximum supported rows and columns |
| 43 | + int maxRow = workbook.MaxRowCount; |
| 44 | + int maxColumns = workbook.MaxColumnCount; |
| 45 | + |
| 46 | + // Display the maximum number of rows and columns supported |
| 47 | + Console.WriteLine("Maximum number of rows supported: " + maxRow.ToString()); |
| 48 | + Console.WriteLine("Maximum number of columns supported: " + maxColumns.ToString()); |
| 49 | +} |
| 50 | +{% endhighlight %} |
| 51 | + |
| 52 | +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} |
| 53 | +Using excelEngine As New ExcelEngine() |
| 54 | + Dim application As IApplication = excelEngine.Excel |
| 55 | + application.DefaultVersion = ExcelVersion.Xlsx |
| 56 | + Dim workbook As IWorkbook = application.Workbooks.Open("Input.xlsx") |
| 57 | + Dim worksheet As IWorksheet = workbook.Worksheets(0) |
| 58 | + |
| 59 | + ' To get the maximum supported rows and columns |
| 60 | + Dim maxRow As Integer = workbook.MaxRowCount |
| 61 | + Dim maxColumns As Integer = workbook.MaxColumnCount |
| 62 | + |
| 63 | + ' Display the maximum number of rows and columns supported |
| 64 | + Console.WriteLine("Maximum number of rows supported: " + maxRow.ToString()) |
| 65 | + Console.WriteLine("Maximum number of columns supported: " + maxColumns.ToString()) |
| 66 | +End Using |
| 67 | +{% endhighlight %} |
| 68 | +{% endtabs %} |
| 69 | + |
| 70 | +A complete working example in C# is present on <a href="https://raw.githubusercontent.com/SyncfusionExamples/XlsIO-Examples/master/FAQ/Maximum%20number%20of%20rows%20and%20columns%20supported/.NET/MaximumNumberOfRowsColumns">this GitHub page</a>. |
0 commit comments