Julian Gonzalez

Generation

generate functionWed, 29 Mar 2023

Read excel file in .Net 6

using Microsoft.Office.Interop.Excel; var xlApp = new Application(); var xlWorkbook = xlApp.Workbooks.Open(fileName); var xlWorksheet = xlWorkbook.Sheets[1]; var xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; //iterate over the rows and columns and print to the console as it appears in the file //excel is not zero based!! for (int i = 1; i <= rowCount; i++) { for (int j = 1; j <= colCount; j++) { //new line if (j == 1) Console.Write("\r\n"); //write the value to the console if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null) Console.Write(xlRange.Cells[

Questions about programming?Chat with your personal AI assistant