Can i get any sample code for trasfering data to MS Excel Topic is solved

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
In need of some credit
In need of some credit
Posts: 4
Joined: Fri Nov 21, 2008 6:52 am
Location: India

Can i get any sample code for trasfering data to MS Excel

Post by RK » Fri Oct 23, 2009 6:54 am

Hi all,

Can any one help me with any sample code, for transfering data to Excel and getting it back using widgets. Something like Import/Export To and From text file ??

Thank you.

Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Oct 23, 2009 5:54 pm

You might need to be a little more specific in what you want to transfer to and from Excel.

Also, are you talking about transferring data with a running instance of Excel or with an Excel file? In the former case you would probably need to use the wxAutomation stuff. In the latter case, you might need to look into something like this:


Post by shepss » Thu Jul 29, 2010 7:36 pm

Of course, and some knowledgeable people among can help you with this

Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 21, 2009 4:02 pm

Post by Tony0945 » Wed Sep 29, 2010 5:01 pm

Code: Select all

void Diet_ManagerFrm::MenuexportClick(wxCommandEvent& event)
   // ExportDialog dlg(this);
    wxString Dieter;
    wxString prompt = wxT("Please Select the Dieter to Export Records for");

    wxSingleChoiceDialog dlg(NULL,prompt,wxT("Export who?"),DieterArray);
    wxFileDialog filedlg(NULL,"Choose the destination file","My Documents","","*.csv",wxFD_SAVE|wxFD_OVERWRITE_PROMPT);  
    if (dlg.ShowModal() != wxID_OK) return;
    Dieter = DieterArray[dlg.GetSelection()];
 //   if (selections.GetCount() < 1) return;  //should not happen
    if (filedlg.ShowModal() != wxID_OK) return;
    wxString path = filedlg.GetPath();
    wxTextFile file(path);
    if (file.Exists())
    file.AddLine("Date      , Dieter, Meal Name,Calories,Total Fat,Saturated Fat,Trans Fat,Cholesterol,"
                "Sodium,Carbohydrate,Fiber,Sugar,Protein,Vitamin A,Vitamin C,Vitamin D,"
    int n,count=DieterRecordArray.GetCount();
    for (n=0; n < count; ++n)
        if (!Dieter.Cmp(DieterRecordArray[n].dieter))
The "ToString" method of the array just outputs the data as a comma separated string. There's probably a better way, but this is working code.

Import would be similar (I didn't implement import).

Post Reply