MFC: Using ODBC to manipulate Excel tables

Source: Internet
Author: User

Scenario One: Leverage ready-made third-party libraries: Cspreadsheet

Use Cspreadsheet the limitations of working with Excel : You can only create tables in Excel before you can manipulate Excel tables in an ODBC way , otherwise the query statement The table name after the from is not filled in .

Limit

the control requires MFC ( Microsoft Foundation Class Library ) support . not tested for support Unicode encoding . Control to ODBC Read-write

An Excel file that requires an ODBC driver . The Excel file must have a column tag . and the first row marks the unique ( field ). prohibited

Delete the workbook, allowing only the workbook contents to be deleted . The column value type refers to the program data type . Do not use Excel format .

Detailed reference:http://blog.csdn.net/andy205214/article/details/5918648

Scenario Two: Write your own Access database

  cdatabase db;//Database library needs to contain header files #include <afxdb.h>  cstring sdriver  = _t ("microsoftexcel driver  (*. XLS);// excel Drive   CString sSql;  charszRecord[6][128] = {0};   ssql.format (_t ("driver={%s};D sn="; Firstrowhasnames=1; Readonly=false; Create_db=\ "%s\";D bq=%s "), Sdriver,strfilepath, strfilepath);   if (!db. OpenEx (Ssql,cdatabase::noodbcdialog))//Connect data source DJB. Xls  {    messagebox (_t ("Failed to open Excel file!"), _t ("error");     return ;   }  //Open Excel Table   crecordset pset (&AMP;DB);   ssql.format (_T (" Selectvalues1,values2 from sheet1 "));   pset. Open (crecordset::forwardonly,ssql,crecordset::readonly);   while (!pset. IsEOF ())   {    pset. GetFieldValue ();//Front field     pset. MoveNext ();   }  db. Close ();

Attention:

1 gets the corresponding property value in the current row by GetFieldValue

2 The sSQL statement is a query statement, where Sheet1 is the table name, stating that the table must be established in the exported file before it can be imported


MFC: Using ODBC to manipulate Excel tables

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.