Reprinted please indicate the origin: http://blog.csdn.net/icyfox_bupt/archive/2011/05/23/6440874.aspx
Basicexcel is a good library for reading Excel.ProgramIt is very convenient. As a beginner, I will discuss the usage of this library.
Basicexcel: The http://www.codeproject.com/KB/office/BasicExcel.aspx also has the library function of basicexcel.
First, create a project named qtexcel. The method used here is the widget. Decompress the files in the downloaded package and include the files basicexcel. HPP and basicexcel. cpp in the project. Is the engineering structure diagram.
Here we do some initialization work.
· Add # include "basicexcel. HPP" to the widget. h ";
· Add # include <qdebug> to the widget. cpp;
Using namespace yexcel;// This is very important because it causes many errors.
Place a Pushbutton in the window, right click and select "go to slot.", and write the following in the automatically generated function in widget. cpp:Code:
Void Widget: on_pushbutton_clicked () <br/>{< br/> basicexcel E; <br/> basicexcelworksheet * sheet1; <br/> E. load ("D:/fox.xls"); <br/> sheet1 = E. getworksheet ("sheet1"); <br/> If (sheet1) <br/>{< br/> size_t maxrows = sheet1-> gettotalrows (); <br/> size_t maxcols = sheet1-> gettotalcols (); <br/> qdebug () <"dimension of" <sheet1-> getansisheetname () <br/> "(" <maxrows <"," <maxcols <")" <Endl; <br/> printf (""); <br/> for (size_t C = 0; C <maxcols; ++ c) printf ("% 10d", C + 1); <br/> qdebug () <Endl; <br/> for (size_t r = 0; r <maxrows; ++ R) <br/>{< br/> qdebug () <("% 10d", R + 1); <br/> for (size_t C = 0; C <maxcols; ++ C) <br/> {<br/> basicexcelcell * cell = sheet1-> cell (R, c); <br/> switch (cell-> type ()) // select the output format <br/> {<br/> case basicexcelcell: undefined: <br/> qdebug () <(""); <br/> break; <br/> case basicexcelcell: INT: <br/> qdebug () <("% 10d", cell-> getinteger ()); <br/> break; <br/> case basicexcelcell: Double: <br/> qdebug () <("% 10.6lf", cell-> getdouble ()); <br/> break; <br/> case basicexcelcell: String: <br/> qdebug () <("% 10 s", cell-> getstring ()); <br/> break; <br/> case basicexcelcell: wstring: <br/> qdebug () <(L "% 10 s ", cell-> getwstring (); <br/> break; <br/>}< br/> qdebug () <Endl; <br/>}< br/>
You can see the output data on the console.