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
RK
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 »

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.
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post 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
shepss

Post by shepss »

Hi!
Of course, and some knowledgeable people among http://www.hasbro.com/en_GB/my-little-pony can help you with this
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

Post 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).
Post Reply