C
Chris Bellini
Greetings! I'm developing a C# application that needs to read some data
from a selected XLS file. I've used VB in the past to automate Excel
but this is the first time I've used C#. Back in VB, I was able to
retrieve a cell's contents via something like this:
Set objExcellApp = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strPathToXLS)
' retrive the contents of A1
strData = objExcel.Cells(1, 1).Value
However, I quickly found out that this was not the case with C#. Thus
far, I have:
objExcel = new Excel.Application();
objWorkbook = (Excel._Workbook)(objExcel.Workbooks._Open(strPath, true,
true, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value));
objSheet = (Excel._Worksheet)objWorkbook.ActiveSheet;
objSheet.Cells[1,1] = "Testing";
// I thought this would store "Testing" in strData
// but it sure doesn't
strData = objSheet.Cells[1,1];
How can I retreive a cell's contents? It could probably be done via
Range() but I'd hate to resort to that, as I like the flexibility that
the ROW,COLUMN format offers. Thanks in advance.
Chris
from a selected XLS file. I've used VB in the past to automate Excel
but this is the first time I've used C#. Back in VB, I was able to
retrieve a cell's contents via something like this:
Set objExcellApp = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(strPathToXLS)
' retrive the contents of A1
strData = objExcel.Cells(1, 1).Value
However, I quickly found out that this was not the case with C#. Thus
far, I have:
objExcel = new Excel.Application();
objWorkbook = (Excel._Workbook)(objExcel.Workbooks._Open(strPath, true,
true, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value));
objSheet = (Excel._Worksheet)objWorkbook.ActiveSheet;
objSheet.Cells[1,1] = "Testing";
// I thought this would store "Testing" in strData
// but it sure doesn't

strData = objSheet.Cells[1,1];
How can I retreive a cell's contents? It could probably be done via
Range() but I'd hate to resort to that, as I like the flexibility that
the ROW,COLUMN format offers. Thanks in advance.
Chris