文件名称:调用excel数据库
文件大小:3.92MB
文件格式:RAR
更新时间:2014-05-01 04:02:31
简单
源代码 void CExcelTestDlg::OnExceltest() { // TODO: Add your control notification handler code here _Application ExcelApp; Workbooks wbsMyBooks; _Workbook wbMyBook; Worksheets wssMysheets; _Worksheet wsMysheet; Range rgMyRge; //创建Excel 服务器(启动Excel) if (!ExcelApp.CreateDispatch("Excel.Application",NULL)) { AfxMessageBox("创建Excel服务失败!"); exit(1); } //利用模板文件建立新文档 wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true); wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t("g:\\exceltest\\MyTemplate.xlt"))); //得到worksheets wssMysheets.AttachDispatch(wbMyBook.GetWorksheets(),true); //得到sheet1 wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t("sheet1")),true); //得到全部的cells,此时,rgMyRge是cells的集合 rgMyRge.AttachDispatch(wsMysheet.GetCells(),true); //设置一行一列的单元的值 rgMyRge.SetItem(_variant_t((long)1),_variant_t((long)1),_variant_t("This is a Excel Test Program!")); //得到所有的列 rgMyRge.AttachDispatch(wsMysheet.GetColumns(),true); //设置第一列 rgMyRge.AttachDispatch(rgMyRge.GetItem(_variant_t((long)1),vtMissing).pdispVal,true); //设置列宽 rgMyRge.SetColumnWidth(_variant_t((long)200)); //调用模版预先存放的宏 ExcelApp.Run(_variant_t("CopyRow"),_variant_t((long)10),vtMissing,vtMissing, vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing, vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing, vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing, vtMissing,vtMissing,vtMissing,vtMissing,vtMissing,vtMissing); //打印浏览 wbMyBook.SetSaved(true); ExcelApp.SetVisible(true); wbMyBook.PrintPreview(_variant_t(false)); //释放内存 rgMyRge.ReleaseDispatch(); wsMysheet.ReleaseDispatch(); wssMysheets.ReleaseDispatch(); wbMyBook.ReleaseDispatch(); wbsMyBooks.ReleaseDispatch(); ExcelApp.ReleaseDispatch(); } MFC调用excel
【文件预览】:
ExcelTest
----ExcelTest.aps(35KB)
----ExcelTestDlg.cpp(6KB)
----Resource.h(687B)
----res()
--------ExcelTest.ico(1KB)
--------ExcelTest.rc2(401B)
----ExcelTest.opt(50KB)
----excel.cpp(166KB)
----ExcelTest.rc(5KB)
----ExcelTest.cpp(2KB)
----ExcelTest.plg(252B)
----StdAfx.cpp(211B)
----ExcelTest.ncb(129KB)
----StdAfx.h(1KB)
----ExcelTest.dsp(4KB)
----excel.h(44KB)
----Debug()
--------StdAfx.obj(103KB)
--------ExcelTest.bsc(5.59MB)
--------ExcelTest.obj(14KB)
--------ExcelTest.exe(224KB)
--------ExcelTest.ilk(416KB)
--------excel.sbr(0B)
--------vc60.idb(217KB)
--------ExcelTestDlg.sbr(0B)
--------ExcelTest.sbr(0B)
--------StdAfx.sbr(1.31MB)
--------ExcelTestDlg.obj(40KB)
--------vc60.pdb(388KB)
--------ExcelTest.res(3KB)
--------ExcelTest.pdb(705KB)
--------excel.obj(629KB)
--------ExcelTest.pch(6.67MB)
----ExcelTest.clw(1KB)
----ExcelTest.dsw(543B)
----ExcelTest.h(1KB)
----ExcelTestDlg.h(1KB)
----ReadMe.txt(4KB)