Last post Oct 17, 2012 12:26 AM by rushik
Oct 17, 2012 12:26 AM|rushik|LINK
In my project, I have requirement to read Macro enabled excel (XLSM file) in C# ASP.Net and save values in appropriate table in Database.
However I can't able to find any solution yet that how to read the XLSM file and get the values from controls like dropdowns and textboxes.
I have tried to read as normal xlsx file like below:
xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open("C:\\Test1.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
int rCnt = 0;
int cCnt = 0;
for (rCnt = 1; rCnt < range.Rows.Count; rCnt++)
for (cCnt = 1; cCnt <= 15; cCnt++)
// Here I didnt get any value from any cell due to excel have values
// in controls not in cell
if ((range.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2 != null)
xlWorkBook.Close(true, null, null);
I have tried to convert it in .XLS file and read it but It didn't work as well.
I need help urgently, so any solutions and suggestions are welcome.