Freshman program Design Teacher, is also our headteacher, has been trying to let us know what C + + can do, once spent a whole 1 of class time to teach us how to find a solution to the problem. He told us to understand Google. However, for my accustomed to Baidu, for a time always change not to come over. However, after this period of time, do know that although occasionally not connected to the server Google is indeed better than Baidu.
Big semester there are a variety of physical experiments, data, and can not be rounding, the formula is very complex, so, decided to use C + + to deal with these data. The beginning is to use TXT file processing, but not intuitive, so, think of our class teacher the first day to show us "C language can do what" when using C operation Excel, so, I also try.
Online tutorials a lot, but most of them are MFC or what, too much trouble. Later, I do not know where a keyword COM component, deep Search, and finally got this:
http://www.technical-recipes.com/2012/how-to-interface-with-excel-in-c/
The whole is still not difficult to understand, after all learned 10几 years of English = =.[CPP] View plain copy #include <iostream> #import "c:\\program files (x86) \\common files\\microsoft shared\\office15\\mso. DLL \ rename ("RGB", "Msorgb") Using namespace Office; #import "c:\\program files (x86) \\common files\\microsoft Shared\\vba\\vba6\\vbe6ext. OLB " using namespace vbide; #import " d:\\microsoft Office\\office15\\excel. EXE " \ rename (" DialogBox ", " Exceldialogbox ") \ rename ("RGB", "Excelrgb") \ rename (" CopyFile ", " Excelcopyfile ") \ rename (" ReplaceText ", " Excelreplacetext ") \ exclude (" IFont ", " IPicture ") no_dual_ Interfaces using namespace std; int main () { hresult hr = coinitializeex (0, coinit_multithreaded); if (FAILED (HR)) { cout << "Failed to initialize com library. error code = 0x " << hex << hr << endl; return hr; } // Create Excel Application Object pointer Create an Excel file pointer Excel::_ApplicationPtr pXL; if&nbSP; (FAILED (Pxl.createinstance ("Excel.Application")) { cout << "Failed to initialize excel:: _application! " << endl; return 0; } // Open the Excel workbook, but don ' t make it visible open a work page pxl->workbooks->open (L "111.xls"); pxl->visible = true; //If true, you can see how the program executes, similar to what we do manually, and false is that it performs its own // access excel worksheet and return pointer to Worksheet cells excel::_worksheetptr pwksheet = pxl->activesheet; excel::rangeptr prange = pwksheet- >Cells; // read an excel data cell. (note excel cells start from index = 1) double value = pRange->Item[1][1]; // Write/modify Excel data cells + save. (reopen xls file to verify) pRange->Item[1][1] = 5.4321; pRange->Item[1][2] = 1.1211; pwksheet->saveas ("112.xls");