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的操作,上网搜罗了一番,大多大同小异,而 ...
随机推荐
- python (3)简单语法:字符串(strip函数),数据类型
一:字符串重复,索引,切片(字符串命令strip) 函数原型strip 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头.结尾处,位于 rm删除序列的 ...
- 值不能为 null 或为空。参数名: linkText
“/”应用程序中的服务器错误. 值不能为 null 或为空.参数名: linkText 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的 ...
- bootstrap-响应式图片、辅助类样式
响应式图片: <div class="container"> <!-- img-responsive 响应式图片 --> <div class=&qu ...
- java调用FFmpeg及mencoder转换视频为FLV并截图
Conver.java package com.ll19.flv; public class Conver { public void run() { try { // 转换并截图 String fi ...
- ppm与毫克/立方米怎么换算
ppm是溶液浓度(溶质质量分数)的一种表示方法,1升水溶液中有1毫克的溶质,g/m3或mg/L. 对于气体:,一百万体积的空气中所含污染物的体积数. 而按我国规定,特别是环保部门,则要求气体浓度以质量 ...
- PostgreSQL在Ubuntu上安装指南
安装环境: Ubuntu 10.04-desktop-i386 PostgreSQL 8.4 1. 安装PostgreSQL 输入如下命令 sudo apt-get install postgresq ...
- Codeforces 622F 「数学数论」「数学规律」
题意: 给定n和k,求 1 ≤ n ≤ 109, 0 ≤ k ≤ 106 思路: 题目中给的提示是对于给定的k我们可以求出一个最高次为k+1的关于n的通项公式. 根据拉格郎日插值法,我们可以通过k+2 ...
- [POJ 2923] Relocation (动态规划 状态压缩)
题目链接:http://poj.org/problem?id=2923 题目的大概意思是,有两辆车a和b,a车的最大承重为A,b车的最大承重为B.有n个家具需要从一个地方搬运到另一个地方,两辆车同时开 ...
- spring项目中使用weblogic的连接池
1.首先在weblogic控制台中配置好一个数据源 我这里建立的数据源的名称叫 jdbc/app1,JNDI名称也叫 jdbc/app1 2.在spring中配置数据源的时候,做如下配置: <b ...
- 海外支付:抵御信用卡欺诈的CyberSource
海外支付:抵御信用卡欺诈的CyberSource 吴剑 2014-06-04 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian 吴剑 http://www.cn ...