MFC Simple Output Excel-(OLE)

Source: Internet
Author: User

three picture wins thousand words :

is Jiangzi :

//Print picking listvoidCknifedlgdlg::P Rintcurusedtabel (intorder) {    //todo:add Your command handler code here    CharSzfilters[] ="hgy Files (*.xls) |*.xls| All Files (*. *) |*.*| |"; CFileDialog Filedlg (FALSE,"xls", Readname +". xls", Ofn_filemustexist|ofn_hidereadonly, Szfilters, NULL); FileDlg.m_ofn.lpstrTitle="Save"; if(Filedlg.domodal () = =IDOK) {CString PathName=Filedlg.getpathname (); Std::vector&LT;STD::MAP&LT;STD::string, std::string>> Resultarr =Yhdialog::getopresultlisttool (_knifeclasses); Std::vector&LT;STD::string>title; Title.push_back ("Material for Materials"); Title.push_back ("thickness"); Title.push_back ("Quantity"); Title.push_back ("Area"); Std::vector&LT;STD::string>Datacol; Datacol.push_back ("panelmatrial"); Datacol.push_back ("Thickness"); Datacol.push_back ("Panelnum"); Datacol.push_back ("allsize"); if(Order = =0)        {            //reverse OrderStd::reverse (Resultarr.begin (), Resultarr.end ());        } onwritedataexcel (PathName, title, Datacol, Resultarr); MessageBox ("Save Complete"); }}//Write ExcelvoidCknifedlgdlg::onwritedataexcel (CString Savepath, STD::VECTOR&LT;STD::string> TITLE,STD::VECTOR&LT;STD::string> DataMap, STD::VECTOR&LT;STD::MAP&LT;STD::string, std::string>>datasrc) {CString strfile=Savepath; COleVariant covtrue (( Short) TRUE), Covfalse (( Short) FALSE), covoptional ((Long) Disp_e_paramnotfound, VT_ERROR);      CApplication app;      CWorkbook Book;      Cworkbooks Books;      Cworksheet sheet;      CWorksheets sheets;      CRange Range;      CFont font; if(!app. CreateDispatch (_t ("Excel.Application")) {MessageBox (_t ("error! creat Excel application Server faile!")); } Books=App.get_workbooks (); Book=Books.      ADD (covoptional); Sheets=book.get_worksheets (); Sheet= Sheets.get_item (COleVariant ( Short)1)); //Get all cellsrange.       AttachDispatch (Sheet.get_cells ());  for(LongTitle_col =0; Title_col < Title.size (); title_col++) {Range.put_item (_variant_t (Long)1),//Line_variant_t ((Long) title_col+1),//column_variant_t (Title[title_col].c_str ()));//Data    }            //here are 1 to 10, 10 digits to the first 10 cells in the second row     for(LongData_row =0; Data_row < Datasrc.size (); data_row++ )      {         for(LongData_col =0; Data_col < Title.size (); data_col++ )          {            Longrow = data_row+2; LongCol = data_col+1;            CString info; Info. Format ("%s", Datasrc[data_row][datamap[data_col]].c_str ()); Range.put_item (_variant_t (row),//Line_variant_t (COL),//column_variant_t (info));//Data        }    }    //SaveBook .       SaveCopyAs (COleVariant (strfile)); Book.put_saved (true); App.put_visible (false); //Releasing Objectsrange.       ReleaseDispatch (); Sheet.       ReleaseDispatch (); Sheets.       ReleaseDispatch (); Book.       ReleaseDispatch (); Books.      ReleaseDispatch (); App.      ReleaseDispatch (); //End, ReleaseBook .         ReleaseDispatch (); Books.         ReleaseDispatch (); App.      ReleaseDispatch (); App.   Quit (); }
MFC OLE EXCEL

MFC Simple Output Excel-(OLE)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.