Last post Aug 27, 2014 03:21 PM by AidyF
Jul 17, 2014 07:50 AM|Hisanth|LINK
I need to read excel cell value in the place of [10,2] with out open excel file. If it is not close this excel file automatically after reading cell value.
string fullFilePath = Path.GetFileName(this.FileUpload1.FileName);
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
ExcelApp.Visible = true;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = ExcelApp.Workbooks.Open(fullFilePath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Microsoft.Office.Interop.Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Microsoft.Office.Interop.Excel.Worksheet excelWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(currentSheet);
var cellValue = (Double)(excelWorksheet.Cells[10,2] as Microsoft.Office.Interop.Excel.Range).Value;
txtValue.Text = cellValue.ToString();
In this code the excel file was opened while read.
Aug 27, 2014 03:08 PM|PatriceSc|LINK
Unclear. You can't read some content found inside a file without opening this file. This code won't work anyway as a web server can't open a client side file (it seems to work on your dev box because the web server and the client machine are the same you
are in the very special case where the web server and the client machine have the same disks).
If you meant you want to use something else than "interop", you can use the OpenXML SDK or a third party product. If you meant you want the user to open an Excel file and interact with your web site, it could be done by having an Excel macro that would transmit
values found in the spreadsheet to your web site.
Else try to explain rather first what you want to do rather than asking about help about how you choosed to do it for now as it seems you choosed a wrong path...
Aug 27, 2014 03:21 PM|AidyF|LINK
//ExcelApp.Visible = true;
ExcelApp.Visible = false;
As already said though, this code has little chance of working on a remote machine. Look to use a component that can read excel files that was designed to run on a website and Microsoft Excel doesn't support what you're trying to do.