BasicExcel library in QT

Source: Internet
Author: User

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;

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

 
 
  1. View plaincopy to clipboardprint? Void Widget: on_pushButton_clicked (){
  2. BasicExcel e;
  3. BasicExcelWorksheet * sheet1;
  4. E. Load ("D:/fox.xls ");
  5. Sheet1 = e. GetWorksheet ("Sheet1 ");
  6. If (sheet1 ){
  7. Size_t maxRows = sheet1-> GetTotalRows ();
  8. Size_t maxCols = sheet1-> GetTotalCols ();
  9. QDebug () <"Dimension of" <sheet1-> GetAnsiSheetName () <
  10. "(" <MaxRows <"," <maxCols <")" <endl;
  11. Printf ("");
  12. For (size_t c = 0; c <maxCols; ++ c) printf ("% 10d", c + 1 );
  13. QDebug () <endl;
  14. For (size_t r = 0; r <maxRows; ++ r ){
  15. QDebug () <("% 10d", r + 1 );
  16. For (size_t c = 0; c <maxCols; ++ c ){
  17. BasicExcelCell * cell = sheet1-> Cell (r, c );
  18. Switch (cell-> Type () // select the output format {
  19. Case BasicExcelCell: UNDEFINED:
  20. QDebug () <("");
  21. Break;
  22. Case BasicExcelCell: INT:
  23. QDebug () <("% 10d", cell-> GetInteger ());
  24. Break;
  25. Case BasicExcelCell: DOUBLE:
  26. QDebug () <("% 10.6lf", cell-> GetDouble ());
  27. Break;
  28. Case BasicExcelCell: STRING:
  29. QDebug () <("% 10 s", cell-> GetString ());
  30. Break;
  31. Case BasicExcelCell: WSTRING:
  32. QDebug () <(L "% 10 s", cell-> GetWString ());
  33. Break;
  34. }
  35. }
  36. QDebug () <endl;
  37. }
  38. }
  39. }
  40. Void Widget: on_pushButton_clicked ()
  41. {
  42. BasicExcel e;
  43. BasicExcelWorksheet * sheet1;
  44. E. Load ("D:/fox.xls ");
  45. Sheet1 = e. GetWorksheet ("Sheet1 ");
  46. If (sheet1)
  47. {
  48. Size_t maxRows = sheet1-> GetTotalRows ();
  49. Size_t maxCols = sheet1-> GetTotalCols ();
  50. QDebug () <"Dimension of" <sheet1-> GetAnsiSheetName () <
  51. "(" <MaxRows <"," <maxCols <")" <endl;
  52. Printf ("");
  53. For (size_t c = 0; c <maxCols; ++ c) printf ("% 10d", c + 1 );
  54. QDebug () <endl;
  55. For (size_t r = 0; r <maxRows; ++ r)
  56. {
  57. QDebug () <("% 10d", r + 1 );
  58. For (size_t c = 0; c <maxCols; ++ c)
  59. {
  60. BasicExcelCell * cell = sheet1-> Cell (r, c );
  61. Switch (cell-> Type () // select the output format
  62. {
  63. Case BasicExcelCell: UNDEFINED:
  64. QDebug () <("");
  65. Break;
  66. Case BasicExcelCell: INT:
  67. QDebug () <("% 10d", cell-> GetInteger ());
  68. Break;
  69. Case BasicExcelCell: DOUBLE:
  70. QDebug () <("% 10.6lf", cell-> GetDouble ());
  71. Break;
  72. Case BasicExcelCell: STRING:
  73. QDebug () <("% 10 s", cell-> GetString ());
  74. Break;
  75. Case BasicExcelCell: WSTRING:
  76. QDebug () <(L "% 10 s", cell-> GetWString ());
  77. Break;
  78. }
  79. }
  80. QDebug () <endl;
  81. }
  82. }
  83. }

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.

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.