Hy, I have to develop an application usign Visual C++ 2008 that should handle (open, change cells and save) some Excel 2003 sheets. I am using .NET Framework 3.5 and the COM reference Interop.Excel.1.5.
Does anyboby knows how to code this?
Thanks.

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

Read the manual.

Here is one way to do it , I think, without the complications of COM. The GUI interface is probably not what you want but you can extract the ideas that document presents.

Here is one way to do it without the complications of COM.

Where? ;)

At OP:
You might want to use CSV-files from excel. The CSV files can easily be opened and edited with C++ because they are plain text, so no need for COM :)

Where? ;)

Oops! link added.

I found the way myself. This is the code that works:

private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) 
        {
        String^ XlsFile = String::Format("Z:\\Documenti\\Lavoro\\Fatture\\2009\\Fattura_02_AEM_marzo_09.xls");
        String^ XlsSheet = String::Format("Milano, {0}/{1}/{2}", 
                                        dateTimePicker1->Value.Day.ToString(),
                                                 dateTimePicker1->Value.Month.ToString(),
                                                 dateTimePicker1->Value.Year.ToString());

        Excel::Application^ oXLApp;
        Excel::Workbook^ oXLWBook;
        //Excel::Sheets^ oXLSheet;
        //Excel::Worksheet^ oXLWSheet;

        Excel::Range^ rng;

        //starts Excel application
        oXLApp = (gcnew Excel::Application());
        oXLApp->Visible = true;
        //opens the workbook of the file "XlsFile"
        oXLWBook = oXLApp->Workbooks->Open(XlsFile, 0, false, 5, "", "",
            true,Excel::XlPlatform::xlWindows, "\t", true, false, 0, false, true, true); 
        //updates the range of sheet1, cell D4
        rng = oXLApp->Range::get("D4","D4");
        rng->Value2 = XlsSheet; 

        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.