October 18th, 2011, 08:17 PM
Excel Automation newbie question
So I am trying to automate excel in CLR/Windows Forms Application.
So the following is what I did.
Removing the un-necessary code...
Question1: I want a specific set of rows from ABC to be copied into one, two and three.
// Defined this somewhere on top.... #define Excel Microsoft::Office::Interop::Excel
Excel::Application^ exApp = gcnew Excel::ApplicationClass();
Workbook^ exWb = exApp->Workbooks->Open(/* a name of a tab formatted text file + other arguments */);
// So I get 1 worksheet from the text file into exWs
//I create 3 more sheets using
//Say the first worksheet hence created is named 'ABC' (name of the textfile)
// I know how to fetch each of these sheets .. using
Worksheet^ exWs2 = safe_cast<Worksheet^>(exApp->ActiveSheet);
// and so forth for 2 and 3 (for simplicity we name these new sheets as 'one', 'two' and 'three')
For, e.g: Row 5 to 11 to be copied in One, Row 12 to 17 in Two, and row 18 to 28 in sheet three.
But, Which rows are copied is dependent on the value of the cell.
For e.g. if(A5==1) then copy row 5 to sheet one.
So, in technical terms I will have to loop from A1 to A50 (or until the cell is empty)
and check for the values.. if A[i] == 1 then append row to Sheet 'one' , else if A[i]==2. then append row to sheet 'two' and so on.
Can someone please help me, in doing that..
I am having a hard time, finding help on VC++ Excel automation. Msdn has more help in C# and VB, but hardly any in VC++.
This Excel Tasks is supposed to be a helpful link. But, the examples are in C# and VB only.
This link Excel Automation samples gives a few examples which parse , in a loop. But again, its not C++.
Question2: How can I perform calculations on the columns. Say for e.g I want to subtract D5: D10 from H5:H10... on the same sheet, and save it as a new column.
May be just a link of website or tutorial which shows this would suffice.
Thank you very much in advance.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!