Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Working with Excel 2003 from a Visual C++ program
I am quite new to programming. Despite that I have to write a C++ program
that opens an .xls workbook, selects a specified worksheet and puts data in specified cells of the worksheet. I have found a document in the Internet that describes how to use the Excel COM model. Based on this I created a program that is able o open a specified .xls workbook and put data in specified cells in the active sheet. However I do not know how to select a specified worksheet so that I do not put the data in the worksheet that ust happens to be active when opening the workbook. How to do that? Here is the code that does what I described: CoInitialize(NULL); Excel::_ApplicationPtr xl; xl.CreateInstance(L"Excel.Application"); xl-Visible = true; xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my documents\\Visual Studio 2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls"); Excel::_WorksheetPtr pSheet = xl-ActiveSheet; Excel::RangePtr pRange = pSheet-Cells; pRange-Item[2][1] = 0.86; pRange-Item[3][1] = "test"; What program lines should I include in order to be able to specify the particular worksheet the data have to go to? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Working with Excel 2003 from a Visual C++ program
I have finally found a solution: Excel::_WorksheetPtr myWrks(xl-Worksheets-Item["Sheet2"]); myWrks-Activate(); So my program looks now this way: CoInitialize(NULL); Excel::_ApplicationPtr xl; xl.CreateInstance(L"Excel.Application"); xl-Visible = true; xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my documents\\Visual Studio 2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls"); Excel::_WorksheetPtr myWrks(xl-Worksheets-Item["Sheet2"]); myWrks-Activate(); Excel::_WorksheetPtr pSheet = xl-ActiveSheet; Excel::RangePtr pRange = pSheet-Cells; pRange-Item[2][1] = 0.86; pRange-Item[3][1] = "test"; "zm01" wrote: I am quite new to programming. Despite that I have to write a C++ program that opens an .xls workbook, selects a specified worksheet and puts data in specified cells of the worksheet. I have found a document in the Internet that describes how to use the Excel COM model. Based on this I created a program that is able o open a specified .xls workbook and put data in specified cells in the active sheet. However I do not know how to select a specified worksheet so that I do not put the data in the worksheet that ust happens to be active when opening the workbook. How to do that? Here is the code that does what I described: CoInitialize(NULL); Excel::_ApplicationPtr xl; xl.CreateInstance(L"Excel.Application"); xl-Visible = true; xl-Workbooks-Open(L"C:\\Documents and Settings\\WRO00724\\my documents\\Visual Studio 2008\\Projects\\Project1\\Excel3\\Excel3\\Example. xls"); Excel::_WorksheetPtr pSheet = xl-ActiveSheet; Excel::RangePtr pRange = pSheet-Cells; pRange-Item[2][1] = 0.86; pRange-Item[3][1] = "test"; What program lines should I include in order to be able to specify the particular worksheet the data have to go to? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Is there a way to unload the loaded XLL file in Excel? Hi all, I amdebugging XLL link library using Visual C++. Everytime I rebuild the XLL, Ihave to close the whole Excel program and relaunch the Excel program again,and then load in the newly gene | Excel Discussion (Misc queries) | |||
Why Excel 2003 VBA program not working in Excel 2007? | Excel Programming | |||
changing the visual basic in office 2003 to visual studio net | Excel Discussion (Misc queries) | |||
Excel 2003 Database Driver Visual FoxPro 7 on Server 2003. | Excel Discussion (Misc queries) |