我用VC作EXCEL的二次开发,
没有import ...“excel.exe”,而是使用了import ...“excel.olb”结果是用这样的定义报错:
Excel::_Application spApp(Application); 改用
使用 CComQIPtr <Excel::_Application> spApp(Application);
就不错,不知道为什么,两者有什么差别,后者使用了ATL的模板?
没有import ...“excel.exe”,而是使用了import ...“excel.olb”结果是用这样的定义报错:
Excel::_Application spApp(Application); 改用
使用 CComQIPtr <Excel::_Application> spApp(Application);
就不错,不知道为什么,两者有什么差别,后者使用了ATL的模板?
你碰到的问题并不是错误!
CComQIPtr< Excel::Workbooks> books;
CComQIPtr< Excel::_Workbook> book; // More object declarations.
CComQIPtr< Excel::Worksheets> sheets;
CComQIPtr< Excel::_Worksheet> sheet; CComQIPtr< Excel::Range> range; // Used for Microsoft Excel 97( & 2000) components. COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); books = app->GetWorkbooks(); // Get an IDispatch pointer.
// to the books object.
book = books->Open("C:\\Test.xls");
sheets = book->GetWorksheets();
sheet = sheets->GetItem( COleVariant((short)(1)) );
range = sheet->GetRange(COleVariant("B3"), COleVariant("b3"));
range->PutItem(COleVariant((long)(1)),COleVariant((long)(1)),COleVariant(LPCTSTR("000666")));
CComQIPtr< IFont> newfont;
newfont = range->GetFont();
newfont->SetName(COleVariant("宋体"));
newfont->SetSize(COleVariant((long)24));
其中sheets = book->GetWorksheets();总是获得一个NULL指针,真是着急呀,不知道为什么?