深入敌后

精通才能算会,深入才能算懂

VC操作EXCEL

COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

 CApplication app;  // app is the Excel _Application object

   // Start Excel and get Application object.

   if(!app.CreateDispatch("Excel.Application"))
   {
      AfxMessageBox("Cannot start Excel and get Application object.");
      return;
   }

   //Make the application visible and give the user control of
   //Microsoft Excel.
   app.put_Visible(TRUE);
   app.put_UserControl(TRUE);

   CWorkbooks books = (CWorkbooks)app.get_Workbooks();
   CWorkbook book = (CWorkbook)books.Add(vOpt);

   CSheets sheets = (CSheets)book.get_Worksheets();
   CWorksheet sheet = (CWorksheet)sheets.get_Item(COleVariant((short)1));
   CRange range = (CRange)sheet.get_Range(COleVariant("A1"),COleVariant("A2"));

   range.put_Value2(COleVariant("test"));

注明:Excel 2002(XP),2003 Range.put_Value(VARIANT RangeValueDataType,VARIANT newValue)有两个参数,Excel 98,2000,只有一个参数,pub_Value2(VARIANT newValue)

阅读更多
个人分类: C/C++
想对作者说点什么? 我来说一句

VC 操作Excel的封装类

2015年07月13日 29KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭