在delphi中XLSReadWriteII.组件的应用实例(1)
第三方组件:XLSReadWriteII.v.5.20.67_XE3
实例源码如下:
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
XLSSheetData5, XLSReadWriteII5,
Vcl.StdCtrls, Vcl.ComCtrls, RzLabel; type
TForm1 = class(TForm)
XLSReadWriteII51: TXLSReadWriteII5;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
pb: TProgressBar;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation
uses strUtils,
XLSDbRead5, Xc12Manager5, Xc12Utils5, XLSUtils5,
Xc12DataStyleSheet5, XLSFormattedObj5, Xc12DataWorksheet5;
{$R *.dfm} type
TDelFlags = set of (dfDelBefore, dfDelAfter); function Delstr(var ms: String; endstr: String; Flags: TDelFlags;
bself: Boolean = True): String;
var
l: Integer;
begin
l := length(endstr);
if dfDelBefore in Flags then
begin
if bself then
begin
Result := copy(ms, 1, pos(endstr, ms) + l - 1);
Delete(ms, 1, pos(endstr, ms) + l - 1);
end
else
begin
Result := copy(ms, 1, pos(endstr, ms) - 1);
Delete(ms, 1, pos(endstr, ms) - 1);
end;
end
else
begin
if bself then
begin
Result := copy(ms, pos(endstr, ms), length(ms));
Delete(ms, pos(endstr, ms), length(ms));
end
else
begin
Result := copy(ms, pos(endstr, ms) + l, length(ms));
Delete(ms, pos(endstr, ms) + l, length(ms));
end;
end;
end; function Matchstrings(Source, pattern: String): Boolean;
var
pSource: array[0..255] of Char;
pPattern: array[0..255] of Char;
function MatchPattern(element, pattern: PChar): Boolean;
function IsPatternWild(pattern: PChar): Boolean;
begin
Result := StrScan(pattern, '*') <> nil;
if not Result then
Result := StrScan(pattern, '?') <> nil;
end;
begin
if 0 = StrComp(pattern, '*') then
Result := True
else if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
Result := False
else if element^ = Chr(0) then
Result := True
else
begin
case pattern^ of
'*':
if MatchPattern(element, @pattern[1]) then
Result := True
else
Result := MatchPattern(@element[1], pattern);
'?':
Result := MatchPattern(@element[1], @pattern[1]);
else
if element^ = pattern^ then
Result := MatchPattern(@element[1], @pattern[1])
else
Result := False;
end;
end;
end;
begin
StrPCopy(pSource, Source);
StrPCopy(pPattern, pattern);
Result := MatchPattern(pSource, pPattern);
end; procedure FindFiles(ASourceDir, SearchFileType: String; var List: TStrings);
var
FileRec: TSearchrec;
Sour: String;
begin
Sour := ASourceDir;
if Sour[length(Sour)] <> '\' then
Sour := Sour + '\';
if FindFirst(Sour + '*.*', faAnyfile, FileRec) = 0 then
{循环}
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if (FileRec.Name <> '.') and (FileRec.Name <> '..') then //找到目录
begin
FindFiles(Sour + FileRec.Name, SearchFileType, List);
end;
end
else //找到文件
begin
{拷贝所有类型的文件}
if Matchstrings(LowerCase(FileRec.Name), SearchFileType) then
begin
List.Add(Sour + FileRec.Name);
end; {拷贝所有类型的文件}
end;
until FindNext(FileRec) <> 0;
FindClose(FileRec);
end; {从磁盘中搜索指定类型的所有文件} procedure SetCellFontStyle(ACell: TXLSCell; AFontStyle: TFontStyles);
var
CellFontStyle : TXc12FontStyles;
begin
CellFontStyle:=[]; if fsBold in AFontStyle then CellFontStyle:=CellFontStyle+[xfsBold];
if fsItalic in AFontStyle then CellFontStyle:=CellFontStyle+[xfsItalic];
if fsStrikeOut in AFontStyle then CellFontStyle:=CellFontStyle+[xfsStrikeOut]; ACell.FontStyle := CellFontStyle; if fsUnderline in AFontStyle then ACell.FontUnderline:=xulSingle;
end; procedure TForm1.Button1Click(Sender: TObject);
var
txtList: TStrings;
i: Integer;
XLS3: TXLSReadWriteII5;
sFileName: string;
sQuezi: string;
sTitle: string;
sBanci: string;
sRiqi: string;
firstRow: Integer;
row: Integer;
readTxt: TStringList;
xlsFileName: string;
zhenwen: string;
j: Integer;
aline: string;
pNnum,kNum: Integer;
eNum: Integer;
AFullXLSXFilePath: string;
AURLOrPath: string;
AText: string;
ATooltip: string;
sNewCellFormat : AxUCString;
begin
button1.Enabled:=false; button1.Caption:='正在生成'; xlsFileName:=Edit2.Text; txtList:=TStringlist.Create ;
findfiles(edit1.Text,'*.txt',txtList); if txtList.Count=0 then Exit; pb.Position:=0;
pb.Max:=txtlist.Count; XLS3 := TXLSReadWriteII5.Create(nil); AFullXLSXFilePath:=xlsFileName;
if UpperCase(ExtractFileExt(AFullXLSXFilePath))='.XLSX' then
XLS3.Version:=xvExcel2007
else
XLS3.Version:=xvExcel97; // XLS3.DirectWrite:=false; XLS3[0].AsString[0, 0] := '日期';
XLS3[0].AsString[1, 0] := '版次';
XLS3[0].AsString[2, 0] := '标题';
XLS3[0].AsString[3, 0] := '缺字';
XLS3[0].AsString[4, 0] := '文件名'; XLS3[0].AsString[5, 0] := '生成时间'; XLS3[0].Cell[0,0].FontStyle:=[xfsBold];
XLS3[0].Cell[1,0].FontStyle:=[xfsBold];
XLS3[0].Cell[2,0].FontStyle:=[xfsBold];
XLS3[0].Cell[3,0].FontStyle:=[xfsBold];
XLS3[0].Cell[4,0].FontStyle:=[xfsBold];
XLS3[0].Cell[5,0].FontStyle:=[xfsBold]; XLS3[0].Columns[0].PixelWidth:=100;
XLS3[0].Columns[1].PixelWidth:=80;
XLS3[0].Columns[2].PixelWidth:=250;
XLS3[0].Columns[3].PixelWidth:=300;
XLS3[0].Columns[4].PixelWidth:=300;
XLS3[0].Columns[5].PixelWidth:=130; XLS3[0].Columns[0].HorizAlignment:=chaLeft; //对齐方式 // sRiqi:=''; sBanci:='';sTitle:='';sQuezi:='';sFileName:=''; firstRow:=0;row:=0; kNum:=0;
readTxt:=TStringList.Create; try // row:=1; for i := 0 to txtList.Count-1 do
begin
pb.Position:=i+1;
application.ProcessMessages ; readTxt.LoadFromFile(txtList[i]); sRiqi:=readTxt.Values['<日期>'];
sBanci:=readTxt.Values['<版次>'];
sTitle:=readTxt.Values['<正题>']; pNnum:=0; sQuezi:=''; eNum:=0; for j := 0 to readTxt.Count-1 do
begin
application.ProcessMessages;
aline:=readTxt.Strings[j]; kNum:=pos('□',aline);
if kNum>0 then
begin
inc(pNnum); //
if length(aline)>=16 then
begin
if sQuezi='' then
begin
sQuezi:=aline;
sQuezi:='('+inttostr(pNnum)+')'+copy(sQuezi,kNum-6,20);
end
else
begin
eNum:=posEx('□',aline,kNum); if eNum-eNum=1 then
begin
kNum:=eNum;
dec(pNnum);
end
else
begin
kNum:=eNum;
sQuezi:=sQuezi+slinebreak+'('+inttostr(pNnum)+')'+copy(aline,kNum-6,20);
end; end; end
else
begin
if sQuezi='' then
sQuezi:='('+inttostr(pNnum)+')'+copy(aline,kNum-6,20)
else
sQuezi:=sQuezi+slinebreak+'('+inttostr(pNnum)+')'+copy(aline,kNum-6,20);
end; end; end;//for j end readTxt.Clear ; if ''<>trim(sQuezi) then inc(row); kNum:=0; eNum:=0; pNnum:=0; //showmessage(sQuezi); // if row=0 then if ''<>trim(sQuezi) then
begin
XLS3[0].AsString[0, row] := sRiqi;
XLS3[0].AsString[1, row] :=sBanci;
XLS3[0].AsString[2, row] := sTitle;
XLS3[0].Cell[2,row].ShrinkToFit:=false;
XLS3[0].Cell[2,row].WrapText:=true; XLS3[0].AsString[3, row] := sQuezi;
XLS3[0].Cell[3,row].FontSize:=12;
XLS3[0].Cell[3,row].ShrinkToFit:=false;
XLS3[0].Cell[3,row].WrapText:=true; // XLS3[0].Cell[4,row].FontStyle:=Xc12DataStyleSheet5.TXc12FontStyles.
XLS3[0].AsString[4, row] :=extractfilename(txtList[i]); AURLOrPath:=txtList[i];
AText:=XLS3[0].AsString[4, row];
ATooltip:=AURLOrPath;
XLS3[0].MakeHyperlink(4,row,AURLOrPath,AText,ATooltip); //超链接 //日期和时间格式
sNewCellFormat:='';
// sNewCellFormat := ExcelStandardNumFormats[XLS_NUMFMT_STD_TIME]; //XLS_NUMFMT_STD_DATE , XLS_NUMFMT_STD_TIME
// sNewCellFormat := 'dd/mm/yyyy hh:mm';
sNewCellFormat := 'dd/mm/yyyy hh:mm:SS';
//sNewCellFormat := 'hh:mm' ;
// sNewCellFormat := 'hh:mm:SS'; XLS3[0].AsDateTime[5,row]:=now;
if sNewCellFormat<>'' then
XLS3[0].Cell[5,row].NumberFormat:=sNewCellFormat; end; sQuezi:=''; end;//for i end
XLS3.SaveToFile(xlsFileName); if pb.Max=pb.Position then
begin
showmessage('生成完毕!'); end; finally
freeandnil(txtlist);
freeandnil(readtxt);
freeandnil(XLS3);
button1.Enabled:=true; button1.Caption:='生成清单';
end; end; procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Clear ;
edit2.Clear ; edit1.Text:='C:\Users\Administrator\Desktop\test';
edit2.Text:='C:\Users\Administrator\Desktop\test\xx.xls';
end; end.
在delphi中XLSReadWriteII.组件的应用实例(1)的更多相关文章
- 在delphi中XLSReadWriteII.组件的应用实例(2)
第三方组件:XLSReadWriteII.v.5.20.67_XE3 实例源码如下: unit Unit1; interface uses Winapi.Windows, Winapi.Messa ...
- Delphi中For In 语法应用实例
一.遍历 TStrings var List: TStrings; s: string; begin List := TStringList.Create; List.CommaText := 'aa ...
- EhLib DBGridEh组件在Delphi中应用全攻略总结(转)
EhLib DBGridEh组件在Delphi中应用全攻略总结(转) http://blog.sina.com.cn/s/blog_94b1b40001013xn0.html 优化SQL查询:如何写出 ...
- delphi 从 TWebbrowse组件中获取图片
在 delphi 中使用 TWebbrowse 组件,虽然效率不如用(idhttp之类)模拟操作效率高.但其难度低,上手快,简单粗暴有效. 从网上搜到的处理此问题的文章大多是 ctrl + c 复制到 ...
- Delphi中Tlist实例
http://blog.163.com/jiandande3218@126/blog/static/74728469201132721428194/ Delphi中Tlist实例 2011-04-27 ...
- 第七十七篇:ref引用(在vue中引用组件实例)
好家伙, 为方便理解, 我们先来写一个经典自增一按钮, 再加上一个count清零按钮, Left.vue组件中: <template> <div > <h1>我是L ...
- delphi列表视图组件(TListView)使用方法|实例
TListView 组件以多种形式显示列表的项目,如详细资料.小图标.大图标等形式表示列表中的项目. 列表视图与用TListBox 组件实现的列表框非常相似.不同的是,列表视图可以让用户选择不同 ...
- Delphi中使用比较少的一些语法
本文是为了加强记忆而写,这里写的大多数内容都是在编程的日常工作中使用频率不高的东西,但是又十分重要. ---Murphy 1,构造和析构函数: a,构造函数: 一般基于TComponent组件的派生类 ...
- 谈Delphi中SSL协议的应用(好多相关文章)
摘要:本文主要介绍如何在Delphi中使用SSL协议.一共分为七个部分:(1)SSL协议是什么?(2)Delphi中如何使用SSL协议?(3)SSL客户端编程实例.(4)SSL服务端编程实例.(5)S ...
随机推荐
- WKWebView 加载本地HTML随笔
一天的时间 解决两个坑~~ 1.加载不出来本地HTML 的JS CSS 样式,问题是引用到项目中 是用的group 这个是错的 直接上图 就知道了 像上图一样,加入相对路径即可,因为如果使用了gro ...
- Arcmap查找孤路
本文将介绍如何查出孤路——如下图红色框中的路: 方法一:使用拓扑检查 1. 使用merge,将所有道路合并到一个图层.注意,不能先分图层进行拓扑检查,因为本不是孤路的数据可能会被挑出来. 2. 对合并 ...
- ElasticSearch(四):关于es的一些基础知识讲解
上一篇博客更新完之后,我发现一个问题:在我创建索引的时候依旧无法准确的理解每个字段的意义,所以就有了这个. 1. 关于索引 1.1 关于索引的一些基础知识 在创建标准化索引的时候,我们传入的请求体如下 ...
- python 进程之间的数据共享
from multiprocessing import Process,Manager import os def f(d,n): d[os.getpid()] = os.getppid()#对字典d ...
- bzoj 2460 线性基
#include<bits/stdc++.h> #define ll long long #define LL long long #define int long long using ...
- Linux 下安装FastDFS v5.08 的php扩展
php扩展也需要依赖于FastDFS一些库文件,所以请先安装FastDFS,具体请看我之前的文章. 一.安装目录 php安装目录 /data/nmp/php FastDFS源码目录 /data/w ...
- PythonStudy——高级语言 High-level programming language
高级语言 高级语言(High-level programming language)相对于机器语言(machine language,是一种指令集的体系.这种指令集,称机器码(machine code ...
- Anaconda安装python(idea兼容)
官方网站www.anaconda.com 1 Windos安装 一路下一步,注意添加环境变量 成功过后,测试一下,打开cmd命令行 2 Linux安装 下载完成后上传到linux bash Anaco ...
- 我发起了一个 操作系统 GUI 和 Tcp / IP 包 的 开源项目 DeviceOS
操作系统 如果 不需要 处理 复杂多样 的 硬件 兼容性, 其实 并不算 大项目, 可以算 毕业设计 . 但是, GUI 和 Tcp / IP 这两个 部分 的 实现逻辑 很多 很复杂, 这 2 ...
- py-day3-2 python 函数递归
# 递归 def calc(n): print(n) if int(n/2) == 0: return n res = calc(int(n/2)) return res res = calc(10) ...