0

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.

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by pferian
0

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.

0

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 :)

0

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; 

        }

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.