一个关于EXCEL读写的问题,请高手帮忙!
我在网上找的代码,是写数据到EXCEL文件,用VC6.0编译运行没有问题
#include <afxdb.h> // this example creates the Excel file C:\DEMO.XLS, puts in a worksheet with two// columns (one text the other numeric) an appends three no-sense records.//void Put2Excel(){ CDatabase database; CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // exactly the same name as in the ODBC-Manager CString sExcelFile = "c:\\demo.xls"; // Filename and path for the file to be created CString sSql; TRY { // Build the creation string for access without DSN sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver,sExcelFile,sExcelFile); // Create the database (i.e. Excel sheet) if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { // Create table structure sSql = "CREATE TABLE demo (Name TEXT,Age NUMBER)"; database.ExecuteSQL(sSql); // Insert data sSql = "INSERT INTO demo (Name,Age) VALUES ('Bruno Brutalinsky',45)"; database.ExecuteSQL(sSql); sSql = "INSERT INTO demo (Name,Age) VALUES ('Fritz Pappenheimer',30)"; database.ExecuteSQL(sSql); sSql = "INSERT INTO demo (Name,Age) VALUES ('Hella Wahnsinn',28)"; database.ExecuteSQL(sSql); } // Close database database.Close(); } CATCH_ALL(e) { TRACE1("Driver not installed: %s",sDriver); } END_CATCH_ALL;} void main(){ Put2Excel();}#include <afxdb.h> // this example creates the Excel file C:\DEMO.XLS, puts in a worksheet with two// columns (one text the other numeric) an appends three no-sense records.//void Put2Excel(LPSTR name, int age){ CDatabase database; CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // exactly the same name as in the ODBC-Manager CString sExcelFile = "c:\\demo.xls"; // Filename and path for the file to be created CString sSql; TRY { // Build the creation string for access without DSN sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver,sExcelFile,sExcelFile); // Create the database (i.e. Excel sheet) if( database.OpenEx(sSql,CDatabase::noOdbcDialog) ) { // Create table structure sSql = "CREATE TABLE demo (Name TEXT,Age NUMBER)"; database.ExecuteSQL(sSql); // Insert data sSql = "INSERT INTO demo (Name,Age) VALUES ("+(CString)name+","+(CString)age+")"; database.ExecuteSQL(sSql); } // Close database database.Close(); } CATCH_ALL(e) { TRACE1("Driver not installed: %s",sDriver); } END_CATCH_ALL;} void main(){ Put2Excel("Bruno",45);}