C++ builder 2010 操作Excel表格的编程实现
//--------------------------------------------------------------------------- #include <vcl.h>
#pragma hdrstop #include "ProcessBar.h"
#include <stdio.h> // For FILE, fopen, fstat, fileno, fread and fclose
#include <sys\stat.h> // For fstat and the stat struct
#include <Math.hpp> // For Min
#include <memory> //For STL auto_ptr class //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm4 *Form4;
//---------------------------------------------------------------------------
__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm4::btn1Click(TObject *Sender)
{
FILE *F;
char MyData[];
long BytesRead; F = fopen("../oui.txt", "r"); // Path relative to Debug
// Use a file larger than 2048 bytes to make it interesting.
if (F)
{
struct stat statbuf;
fstat(fileno(F), &statbuf);
pb1->Max = statbuf.st_size;
if (pb1->Max > )
{
pb1->Step = (pb1->Max)/;
pb1->Step = Min(pb1->Step, );
}
else
pb1->Step = pb1->Max;
std::auto_ptr<char> DataBuffer(new char[pb1->Step]);
for (pb1->Position = ;
pb1->Position < pb1->Max;
pb1->StepIt()) // Move the ProgressBar Position using StepIt.
{
fread(DataBuffer.get(), pb1->Step, , F);
// Do this or else the read wraps and starts over.
pb1->Step =
Min(pb1->Step, pb1->Max - pb1->Position);
} mmo1->Lines->Add(DataBuffer.get()); fclose(F);
DataBuffer.release();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm4::btn2Click(TObject *Sender)
{ Variant vExcelApp, vWorkbook, vRange, Sheet1;
vExcelApp = Variant::CreateObject("Excel.Application");
vExcelApp.OlePropertySet("Visible", false);
vExcelApp.OlePropertyGet("WorkBooks").OleProcedure("Open",
dlgOpen1->FileName.c_str());
vWorkbook = vExcelApp.OlePropertyGet("ActiveWorkbook"); int BookCount = vWorkbook.OlePropertyGet("Sheets").OlePropertyGet
("Count");
for (int i = ; i < BookCount; i++)
{
AnsiString SheetName = vWorkbook.OlePropertyGet("Sheets", i + )
.OlePropertyGet("Name");
// ShowMessage(SheetName); } // Sheet1 = vWorkbook.OlePropertyGet( "ActiveSheet ");
// vExcelApp.Exec(PropertyGet( "Cells ") < <1 < <3).Exec(PropertySet( "Value ") < <15); //赋值
// Sheet1.OlePropertyGet( "Rows ", 1).OlePropertyGet( "Insert "); //插入
String kkl, hgf;
int it = , st = ; while (it > && BookCount >= st)
{
vWorkbook.OlePropertyGet("Sheets", st).OleProcedure("Select");
// 选择sheet
for (it = ; it <= ; it++)
{
kkl = vExcelApp.Exec(PropertyGet("Cells") << << it);
//if (kkl.Pos(qz1) > 0 || kkl.Pos(qz2) > 0) // 读取
break;
}
st++;
} int kk = ;
for (kk = ; kk <= ; kk++)
{
kkl = vExcelApp.Exec(PropertyGet("Cells") << kk << it);
//if (kkl.Pos(qz1) > 0 || kkl.Pos(qz2) > 0) // 读取
break;
} hgf = vExcelApp.Exec(PropertyGet("Cells") << kk << it + );
int ki = ;
while (hgf.Trim() != "")
{
if (ki == StringGrid2->RowCount - )
//StringGrid1->RowCount++;
// kkl==vExcelApp.Exec(PropertyGet( "Cells ") < <kk < <it); StringGrid2->Cells[][ki] = vExcelApp.Exec
(PropertyGet("Cells") << kk << it); // 2-4列的数据
StringGrid2->Cells[][ki] = vExcelApp.Exec
(PropertyGet("Cells") << kk << it + );
StringGrid2->Cells[][ki] = vExcelApp.Exec
(PropertyGet("Cells") << kk << it + );
kk++;
ki++;
hgf = vExcelApp.Exec(PropertyGet("Cells") << kk << it + );
} vExcelApp.OlePropertyGet("ActiveSheet").OlePropertyGet("Cells ", , )
.OleProcedure("Select");
vRange = vExcelApp.OlePropertyGet("Selection");
vRange.Exec(Function("Sort") << vExcelApp.OlePropertyGet("Selection")
<< ); // vWorkbook.OleProcedure( "Save");
vWorkbook.OleProcedure("Close");
vExcelApp.OleFunction("Quit");
vWorkbook = Unassigned;
vExcelApp = Unassigned;
}
// ---------------------------------------------------------------------------
C++ builder 2010 操作Excel表格的编程实现的更多相关文章
- VS2010 C++ 操作Excel表格的编程实现
转载请注明原文网址: http://www.cnblogs.com/xianyunhe/archive/2011/09/25/2190485.html 通过VC实现对Excel表格的操作的方法有多种, ...
- qt 操作excel表格
自己编写的一个Qt C++类,用于操作excel表格,在Qt中操作excel需在.pro中增加CONFIG+=qaxcontainer配置. 1.打开Excel:objExcel = new QAx ...
- Python 利用Python操作excel表格之openyxl介绍Part2
利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436) ## 绘图 c = LineChart() ...
- Python 利用Python操作excel表格之openyxl介绍Part1
利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436),免费获取以下性能监控工具(类似Nmon精简版) ...
- 【转】python操作excel表格(xlrd/xlwt)
[转]python操作excel表格(xlrd/xlwt) 最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异, ...
- Python 利用Python操作excel表格之xlwt介绍
利用Python操作excel表格之xlwt介绍 by:授客 QQ:1033553122 直接上代码 案例1 #!/usr/bin/env python # -*- coding:utf-8 ...
- 用NPOI、C#操作Excel表格生成班级成绩单
在C#中利用NPOI操作Excel表格非常方便,几乎上支持所有的Excel表格本身所有的功能,如字体设置.颜色设置.单元格合并.数值计算.页眉页脚等等. 这里准备使用NPOI生成一个班级成绩单Exce ...
- python - 操作excel表格
说明:由于公司oa暂缺,人事妹子在做考勤的时候,需要通过几个excel表格去交叉比对员工是否有旷工或迟到,工作量大而且容易出错. 这时候it屌丝的机会来啦,花了一天时间给妹子撸了一个自动化脚本. 1. ...
- 转载:python操作excel表格(xlrd/xlwt)
python操作excel表格(xlrd/xlwt) 最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异,而 ...
随机推荐
- POJ 1556 The Doors(线段交+最短路)
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...
- (转)zookeeper学习记录--附browser
转自:http://agapple.iteye.com/blog/1111377 背景 前段时间看了S4流计算引擎,里面使用到了zookeeper进行集群管理,所以也就花了点时间研究了下zookeep ...
- 并发容器之ConcurrentSkipListSet
概要 本章对Java.util.concurrent包中的ConcurrentSkipListSet类进行详细的介绍.内容包括:ConcurrentSkipListSet介绍ConcurrentSki ...
- role在标签中的作用是什么?
html 里面的 role 本质上是增强语义性,当现有的HTML标签不能充分表达语义性的时候,就可以借助role来说明.通常这种情况出现在一些自定义的组件上,这样可增强组件的可访问性.可用性和可交互性 ...
- apache下php无法解析直接显示源代码解
在http.conf中加入php的设置 #php5_start phpIniDir "d:/Program Files/php" LoadModule php5_module &q ...
- SelectedValue 失效
/// <summary> /// 绑定代表下拉选项 /// </summary> public void BindOwnerDataII(string unitId, str ...
- Oracle自增列
一.介绍: 在设计数据库时,有时候希望表的某一列为自增列,例如编号,本文就介绍如何在oracle数据库中实现自增列,需要两个步骤: 1)构建序列(sequence) 在oracle中sequence就 ...
- mysql start server faild
可能没卸载干净...在安装mysql数据库时,如果重新安装,很容易遇见apply security setting error,即在配置mysql启动服务时,在启动apply security set ...
- Android——主流分辨率
VGA:480*640 QVGA:240*320 HVGA:320*480 WVGA:480*800 FWVGA:480*854 IntelHaxm.exe 模拟器加速器
- HDU 4118 Holiday's Accommodation
Holiday's Accommodation Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 200000/200000 K (Jav ...