基于excel9.h的excel处理;
#include "excel9.h"#includeusing namespace std;class excel_lwn{ public: excel_lwn() { CoInitialize(NULL); if(!app.CreateDispatch(_T("Excel.Application"),NULL)) { /*"启动Excel服务器失败!" */ } f_result = NULL; flag=-1; } ~excel_lwn() { book.SetSaved(TRUE); books.Close(); app.Quit(); } void OpenTable(CString excelName, int table=1) { books=app.GetWorkbooks(); COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); lpDisp = books.Open(excelName, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional); book.AttachDispatch( lpDisp ); sheets=book.GetSheets(); sheet=sheets.GetItem(COleVariant((short)table)); } void GetValue(int i=1,int lie=1) { char c_lie[2]; c_lie[0] =64+ lie; c_lie[1]= '\0'; cs_lie=c_lie; char c_hang[11]; itoa(i,c_hang, 10); cs_hang=c_hang; Range range=sheet.GetRange(COleVariant(cs_lie+cs_hang),COleVariant(cs_lie+cs_hang)); COleVariant rValue= range.GetValue(); isSuccess = rValue.vt; if (rValue.vt ==VT_BSTR ) { //MessageBox(NULL,CString(rValue.bstrVal),TEXT("你好"),MB_ICONINFORMATION|MB_YESNO); cs_result = rValue.bstrVal; flag=1; } if (rValue.vt ==VT_R8 ) { //cout< <
相关文件:http://pan.baidu.com/s/1hqfBn72
c#中关于excel的处理: http://www.codeproject.com/Tips/813187/Csharp-Read-and-write-Excel-xls-and-xlsx-files-con