Initial use of the basicexcel library in QT

Source: Internet
Author: User

Reprinted please indicate the origin:


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 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.


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: 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.