Page 1 of 1

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

Posted: Fri Oct 23, 2009 6:54 am
by RK
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.

Posted: Fri Oct 23, 2009 5:54 pm
by timg
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:

http://www.codeproject.com/KB/office/BasicExcel.aspx

Posted: Thu Jul 29, 2010 7:36 pm
by shepss
Hi!
Of course, and some knowledgeable people among http://www.hasbro.com/en_GB/my-little-pony can help you with this

Posted: Wed Sep 29, 2010 5:01 pm
by Tony0945

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.Open();
    }
    else
    {
        file.Create();
    }
    file.Clear();
    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,"
                "Calcium,Iron");
    int n,count=DieterRecordArray.GetCount();
    for (n=0; n < count; ++n)
    {
        if (!Dieter.Cmp(DieterRecordArray[n].dieter))
        {
            file.AddLine(DieterRecordArray[n].ToString());
        }
    }
    file.Write();
    file.Close();
}
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).