|
| 1 | +--- |
| 2 | +title: How to read all values of a column | Syncfusion |
| 3 | +description: This page explains how to read all values of a column 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 read all values from a column in an Excel worksheet? |
| 10 | + |
| 11 | +The following code example illustrates how to read all values from a specific column in an Excel worksheet using XlsIO in C# (cross-platform and Windows-specific) and VB.NET. |
| 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 | + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); |
| 20 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 21 | + |
| 22 | + // Select the column |
| 23 | + string columnName = "E"; |
| 24 | + foreach (IRange row in sheet.Rows) |
| 25 | + { |
| 26 | + // Read all the value of a column |
| 27 | + var val = sheet[columnName + row.Row].Value; |
| 28 | + } |
| 29 | +} |
| 30 | +{% endhighlight %} |
| 31 | + |
| 32 | +{% highlight c# tabtitle="C# [Windows-specific]" %} |
| 33 | +using (ExcelEngine excelEngine = new ExcelEngine()) |
| 34 | +{ |
| 35 | + IApplication application = excelEngine.Excel; |
| 36 | + application.DefaultVersion = ExcelVersion.Xlsx; |
| 37 | + IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/InputTemplate.xlsx")); |
| 38 | + IWorksheet worksheet = workbook.Worksheets[0]; |
| 39 | + |
| 40 | + // Select the column |
| 41 | + string columnName = "E"; |
| 42 | + foreach (IRange row in sheet.Rows) |
| 43 | + { |
| 44 | + // Read all the value of a column |
| 45 | + var val = sheet[columnName + row.Row].Value; |
| 46 | + } |
| 47 | +} |
| 48 | +{% endhighlight %} |
| 49 | + |
| 50 | +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} |
| 51 | +Using excelEngine As ExcelEngine = New ExcelEngine() |
| 52 | + Dim application As IApplication = excelEngine.Excel |
| 53 | + application.DefaultVersion = ExcelVersion.Xlsx |
| 54 | + Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx") |
| 55 | + Dim worksheet As IWorksheet = workbook.Worksheets(0) |
| 56 | + |
| 57 | + ' Select the column |
| 58 | + Dim columnName As String = "E" |
| 59 | + For Each row As IRange In worksheet.Rows |
| 60 | + Dim cellAddress As String = columnName & row.Row.ToString() |
| 61 | + ' Read all the value of a column |
| 62 | + Dim val = worksheet(cellAddress).Value |
| 63 | + Next |
| 64 | +End Using |
| 65 | +{% endhighlight %} |
| 66 | +{% endtabs %} |
0 commit comments