http://blog.vckbase.com/dlutyuanhongl/archive/2005/03/20/3746.html
时常在论坛上看到有人问这个VC操作Word或者Excel有没有书系统地介绍如何去做,有这个必要吗?其实捅破这层窗户纸,你就会恍然大悟,原来是这么回事啊!在此我觉得有必要把我工作中操纵Excel的一点小体会拿出来和大家共享,也许对初学者能有所帮助,高手就不要看了。操作Word请看牛人yingkou的BLOG(http://blog.vckbase.com/yingkou) .基本步骤如下:
一、Excel的层次结构
Application
Workbooks
Workbook
......
Worksheets
Worksheet
......
Range
Font
Borders
......
.......
二、插入类型库
1、在一个已有的MFC工程按Ctrl + W 弹出ClassWizard对话框。
2、Add Class...\From a type Library... 在 Office 目录中,找到你想使用的Excel类型库(Offce2000下,此目录在C:\Program Files\Microsoft Office\Office\EXCEL9.OLB)。选择EXCEL9.OLB此类型文件。
3、在弹出的对话框中选择要添加的类,具体选那些类要根据实际情况而定。当然你也可以全选。
三、基本操作
当你要选用Excel生成报表时,表的结构可能有固定的部分,这时做一个模板,这样可以减少编码的负担。加载Excel模板的代码如下。

Workbooks wbsBooks;
_Workbook wbBook;
Worksheets wssSheets;
_Worksheet wsSheet;
Range rngXls;
FontXls font; // 字体
BordersXls border; // 边框
// 初始化Com














ExcelApp.SetVisible(FALSE); // 隐藏










NULL,
NULL,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
"模版||*.xlt||",
NULL );


















wsSheet.SetName( "Your Sheet" ); // 改名
// 得到全部Cells,此时,rngXls 是cells的集合
rngXls = wsSheetAcc.GetCells();






我们知道在Excel中每个单元格可以用A1,A2,C3的形式来表示。譬如获得A1到C5之间单元格集可以这样实现,rngXls = rngXls.GetRange( COleVariant(_T(“A1“)),COleVariant(_T(“C5“)) );但是我们习惯用坐标形式如(1,1),(2,1)来表示每个单元格,在上述操作中,就没有办法用我们习惯的坐标的形式实现。它们之间如何转换那?这个用如下函数实现.













