Retrieving data from Excel

  • Hello

    After some "exercising" I was able to send easily data from my VisualC++.NET (EE) application to Excel. After referencing the corresponding interop (the interop Microsoft Excel 10.0 Type Library), I could send the data to the corresponding worksheet using the following code:


    //open link to Excel:
    Microsoft::Office::Interop::Excel::Application^ xlApp = gcnew Microsoft::Office::Interop::Excel::ApplicationClass();

    //open Excel file:
    Workbook^ wb = xlApp->Workbooks->Open("C:\\dummy.xls", System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value, System::Reflection::Missing::Value);

    xlApp->Visible = true;

    //set active worksheet (here for example worksheet nb. 1):
    static_cast<Worksheet^>(xlApp->ActiveWorkbook->Sheets->Item[(1)])->Select(Type::Missing);

    Worksheet^ sheet = dynamic_cast<Microsoft::Office::Interop::Excel::Worksheet^>(wb->ActiveSheet);


    After that, I could simply send the data by the command

    sheet->Cells[line, column] = number;


    My question: How can I retrieve the value stored in a cell of Excel??? I thought it would work with

    number = sheet->Cells[line, column];

    But this gives a format error. Has anyone an idea - the solution must be simple...

    Thanks a lot for your help,

    B E A T

    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress, WoltLab & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!