com_excel之CWorkBooks
来源:互联网 发布:电子电路仿真软件下载 编辑:程序博客网 时间:2024/06/07 17:04
Workbooks Members
A collection of all the Workbook objects that are currently open in the Microsoft Excel application.
The following tables list the members exposed by the Workbooks type.
测试:
COleVariant covTrue((short)TRUE);
COleVariant covFalse((short)FALSE);
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
Open:打开一个已存在的excel文件
/*
* 打开一个excel文件
**/
string path = "D:\\test_big_file.xls";
LPDISPATCH lpdis = books.Open(path.c_str(), covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional);
books.Close();
如果文件不存在就报异常
Close:关闭全部workbook,如果想只关闭一个就需要设置workbook的自动关闭宏不启动
Closing a workbook using the Close method doesn't run any Auto_Close macros in the workbook. Use theRunAutoMacros method to run the auto close macros.
Add:新建一个excel文件
LPDISPATCH Add(VARIANT& Template)
- 参数Template
Optional Object. Determines how the new workbook is created. If this argument is a string specifying the name of an existing Microsoft Excel file, the new workbook is created with the specified file as a template. If this argument is a constant, the new workbook contains a single sheet of the specified type. Can be one of the followingXlWBATemplate constants:xlWBATChart, xlWBATExcel4IntlMacroSheet,xlWBATExcel4MacroSheet, orxlWBATWorksheet. If this argument is omitted, Microsoft Excel creates a new workbook with a number of blank sheets (the number of sheets is set by theSheetsInNewWorkbook property).
由于没有导出excel14的枚举值 add的第二种情况没有测试
add的第三种情况 默认: lpdis2 = books.Add(covOptional);
OpenText:打开文本文件
path = "D:\\test_big_file.txt";
books.OpenText(path.c_str(), covOptional, covOptional, covOptional, 1, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional);
属性:Item
可以通过get_Item()函数获取值
可以根据参数index取得books里的指定book对象
ps: 可以用get_Item()和get_count()遍历books集合
books的另外一个测试结果:
Open Add OpenText三个函数的区别:
说明:excel服务处理excel文件或是文本文件都需要加载到内存
1:Open 内存对象和磁盘对象(文件)是关联的:改变内存的值,使用cworkbook的save,磁盘文件也会被相应的改变
2:Add 新建,通过名字就知道内存里的文件是新的,使用add的三种用法中的第一种(拷贝磁盘文件的副本到内存, 详细用法请看Add函数的说明),这时,内存里的任何操作与磁盘文件没有半点关系 保存的时候需要用到cworkbook的SaveCopyAs()函数,具体在下一节详说
3:OpenText同Open,但是有一点需要注意的是,opentext加载会非常慢,因为他需要检查没一个项值的属性:eg: 是否用“”包裹,用什么分割域等等。。检查的多了耗时也多,所以不推荐用opentext
因为我也是边学边记录 肯定会有些错误的地方, 我写到的地方大家最好重测一下
- com_excel之CWorkBooks
- CWorkBooks、CWorkBook、CWorkSheets、CWorkSheet、CRange简介
- 导入MFC Lib库中的 CApplication、CRange、CWorkBook、CWorkBooks、CWorkSheet
- VS2010操作Excel,在CWorkbooks.Open时出现服务器出现意外情况
- 復之之理
- 博学之,审问之,慎思之,明辨之,笃行之
- 博学之,审问之,慎思之,明辨之,笃行之
- 雪,之韵,之恋,之......
- 年终总结之天涯之无敌之言论
- 万源之源之drupal 之 drupal_flush_all_caches
- 编程之美------之数字之魅
- 之记录员
- 孔乙己之
- 浩杂收之
- “##”之作用
- vc++之
- 尽力而为之
- 怀念之。。。
- oracle 队列表
- 实验:《不恢复余数的阵列除法器》
- 在sqlplus下去修改oracle用户的密码和解锁用户
- How To Perform a Full Export And Exclude Certain Schemas Using The Data Pump API? [ID 1340781.1]
- QTP同步的几种方法
- com_excel之CWorkBooks
- 常用正则表达式
- KeilC 生成lib文件实例
- ViewController生命周期
- namenode的机器也变成了tasktracker节点
- Winform中利用Graphics 画折线图
- horizon中列表的连接默认以主键为传递参数,如果想以其他为传递参数
- 5天学会jaxws-webservice编程第一天 .
- pthread_cancel用法及常见问题