R
riversr
I am an absolute beginner with VSTO and Excel. I am using VS 2008 Express.
I've been able to execute a few very basic steps by creating a reference to
the Microsoft Excel 12.0 Object Library COM object. That allowed me to start
an Excel app and at least view the workbook object. My question is this. I
want to do some basic cell operations. It seems that I do not understand the
Excel object model. I assumed that if I created the Excel App, then I would
be able to access the sub-ordinate Workbooks collection and then the
Worksheets collection and eventually the cells on the worksheet, but it
hasn't worked.
Here's my code:
Excel.Application myApp = new Excel.Application();
myApp.Visible = true;
myApp.StatusBar = "Hello World";
//This line loads a workbook from an existing csv file
myApp.Workbooks.Open(@"c:\trash\xl.csv", missing, false,
missing, missing, missing, missing, missing, ",", true, missing, missing,
true, missing, missing);
//This line allows me to see the name of the workbook
string name = myApp.Workbooks[1].Name;
Then I would think that I could access the worksheet inside the workbook
with something like this, but it does not work:
string name2 = myApp.Worksbooks[1].WorkSheets[1].Name
Do I need to create a worksheet? I can see the open Excel application and
the three default worksheets are there.
Please someone, help me understand the proper way to access the worksheet
and then the cells on it. It seems there is very little information on the
web that provides good examples of this. Help!
riversr
I've been able to execute a few very basic steps by creating a reference to
the Microsoft Excel 12.0 Object Library COM object. That allowed me to start
an Excel app and at least view the workbook object. My question is this. I
want to do some basic cell operations. It seems that I do not understand the
Excel object model. I assumed that if I created the Excel App, then I would
be able to access the sub-ordinate Workbooks collection and then the
Worksheets collection and eventually the cells on the worksheet, but it
hasn't worked.
Here's my code:
Excel.Application myApp = new Excel.Application();
myApp.Visible = true;
myApp.StatusBar = "Hello World";
//This line loads a workbook from an existing csv file
myApp.Workbooks.Open(@"c:\trash\xl.csv", missing, false,
missing, missing, missing, missing, missing, ",", true, missing, missing,
true, missing, missing);
//This line allows me to see the name of the workbook
string name = myApp.Workbooks[1].Name;
Then I would think that I could access the worksheet inside the workbook
with something like this, but it does not work:
string name2 = myApp.Worksbooks[1].WorkSheets[1].Name
Do I need to create a worksheet? I can see the open Excel application and
the three default worksheets are there.
Please someone, help me understand the proper way to access the worksheet
and then the cells on it. It seems there is very little information on the
web that provides good examples of this. Help!
riversr