Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# Read Excel columns header return to list

 /// <summary>
        /// Read excel columns header return to List
        /// </summary>
        /// <param name="file">ecel file path</param>
        /// <returns>List</returns>

///Note 1. Install-Package Epplus, 2. Use OfficeOpenXml namespace
        public static List<string> ReadExcelHealdersStoretoList(FileInfo file)
        {
            List<string> excelColumns = new List<string>();
            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            //Read excel columns headers store to list
            using (var package = new ExcelPackage(file))
            {
                ExcelWorksheet workSheet = package.Workbook.Worksheets[0];
                foreach (var firstRC in workSheet.Cells[1, 1, 1, workSheet.Dimension.End.Column])
                {
                    excelColumns.Add(firstRC.Text);
                }
            }

            return excelColumns;
        }
 
PREVIOUS NEXT
Tagged: #Read #Excel #columns #header #return #list
ADD COMMENT
Topic
Name
5+4 =