How to get specific column header and its value in excel using ASP.NET MVC C# Example: I need to fine the header column name "All Section", but this column is positioned dynamically. some times there were "All Section" in column D, E, AA etc. Once I found all these header ("All Section"), then I need to get it's column value and sum its total. Thank you very much in advance. just need some guidelines or sample code here.
Here's my initial code using this <pre>using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using Excel = Microsoft.Office.Interop.Excel;
public static List<Tuple<int, string>> GetExcelNamesPerFile(string reportFileName, ref Error error) { List<Tuple<int, string>> excelNamesPerFile = new List<Tuple<int, string>>(); int? reportFileID = null; try { // get excelFile ID using (var dbContext = new EXCELEntities()) { reportFileID = (from reportFile in dbContext.R_ReportFile where reportFile.FileName == reportFileName select reportFile.ID).First(); } // get excel names using (var dbContext = new EXCELEntities()) { var excelReports = (from reportsDB in dbContext.SchedNo_Loc where reportsDB.ReportFile_ID == reportFileID select reportsDB).ToList(); foreach (var item in excelReports) { excelNamesPerFile.Add(new Tuple<int, string>(item.ReportFile_ID, item.ScheduleNo)); } } } catch (Exception ex) { error = new Error() { ErrorCode = "-99", ErrorMessage = ex.Message }; return reportNamesPerFile; } return excelNamesPerFile; }
using Excel = Microsoft.Office.Interop.Excel;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)