This article introducesQTLowerBasicExcelInitial database experience,BasicExcelIt is a good library for reading excel, which is very convenient for small programs. As a beginner, I will discuss the usage of this library at the beginning.
BasicExcelOf: http://www.codeproject.com/KB/office/BasicExcel.aspx is also attachedBasicExcelLibrary function.
First, create a project named qtexcel. The method used here is the widget. Decompress the files in the downloaded package and include the files in the project.BasicExcel. Hpp andBasicExcel. Cpp files. Is the engineering structure diagram.
Here we do some initialization work.
1. Add # include "BasicExcel. hpp" to the widget. h ";
2. Add # include <QDebug> to the widget. cpp;
- Using namespace YExcel; // This is very important because it causes many errors.
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 code in the automatically generated function in the widget. cpp:
- View plaincopy to clipboardprint? Void Widget: on_pushButton_clicked (){
- BasicExcel e;
- BasicExcelWorksheet * sheet1;
- E. Load ("D:/fox.xls ");
- Sheet1 = e. GetWorksheet ("Sheet1 ");
- If (sheet1 ){
- Size_t maxRows = sheet1-> GetTotalRows ();
- Size_t maxCols = sheet1-> GetTotalCols ();
- QDebug () <"Dimension of" <sheet1-> GetAnsiSheetName () <
- "(" <MaxRows <"," <maxCols <")" <endl;
- Printf ("");
- For (size_t c = 0; c <maxCols; ++ c) printf ("% 10d", c + 1 );
- QDebug () <endl;
- For (size_t r = 0; r <maxRows; ++ r ){
- QDebug () <("% 10d", r + 1 );
- For (size_t c = 0; c <maxCols; ++ c ){
- BasicExcelCell * cell = sheet1-> Cell (r, c );
- Switch (cell-> Type () // select the output format {
- Case BasicExcelCell: UNDEFINED:
- QDebug () <("");
- Break;
- Case BasicExcelCell: INT:
- QDebug () <("% 10d", cell-> GetInteger ());
- Break;
- Case BasicExcelCell: DOUBLE:
- QDebug () <("% 10.6lf", cell-> GetDouble ());
- Break;
- Case BasicExcelCell: STRING:
- QDebug () <("% 10 s", cell-> GetString ());
- Break;
- Case BasicExcelCell: WSTRING:
- QDebug () <(L "% 10 s", cell-> GetWString ());
- Break;
- }
- }
- QDebug () <endl;
- }
- }
- }
- Void Widget: on_pushButton_clicked ()
- {
- BasicExcel e;
- BasicExcelWorksheet * sheet1;
- E. Load ("D:/fox.xls ");
- Sheet1 = e. GetWorksheet ("Sheet1 ");
- If (sheet1)
- {
- Size_t maxRows = sheet1-> GetTotalRows ();
- Size_t maxCols = sheet1-> GetTotalCols ();
- QDebug () <"Dimension of" <sheet1-> GetAnsiSheetName () <
- "(" <MaxRows <"," <maxCols <")" <endl;
- Printf ("");
- For (size_t c = 0; c <maxCols; ++ c) printf ("% 10d", c + 1 );
- QDebug () <endl;
- For (size_t r = 0; r <maxRows; ++ r)
- {
- QDebug () <("% 10d", r + 1 );
- For (size_t c = 0; c <maxCols; ++ c)
- {
- BasicExcelCell * cell = sheet1-> Cell (r, c );
- Switch (cell-> Type () // select the output format
- {
- Case BasicExcelCell: UNDEFINED:
- QDebug () <("");
- Break;
- Case BasicExcelCell: INT:
- QDebug () <("% 10d", cell-> GetInteger ());
- Break;
- Case BasicExcelCell: DOUBLE:
- QDebug () <("% 10.6lf", cell-> GetDouble ());
- Break;
- Case BasicExcelCell: STRING:
- QDebug () <("% 10 s", cell-> GetString ());
- Break;
- Case BasicExcelCell: WSTRING:
- QDebug () <(L "% 10 s", cell-> GetWString ());
- Break;
- }
- }
- QDebug () <endl;
- }
- }
- }
You can see the output data on the console.
Summary: This article introducesQTLowerBasicExcelFirst-time experience of the database. The content is introduced here. Through the above operations, is it easy to implement. We hope the above content can help you solve the problem.