第三方组件: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)的更多相关文章

  1. 在delphi中XLSReadWriteII.组件的应用实例(2)

    第三方组件:XLSReadWriteII.v.5.20.67_XE3 实例源码如下:   unit Unit1; interface uses Winapi.Windows, Winapi.Messa ...

  2. Delphi中For In 语法应用实例

    一.遍历 TStrings var List: TStrings; s: string; begin List := TStringList.Create; List.CommaText := 'aa ...

  3. EhLib DBGridEh组件在Delphi中应用全攻略总结(转)

    EhLib DBGridEh组件在Delphi中应用全攻略总结(转) http://blog.sina.com.cn/s/blog_94b1b40001013xn0.html 优化SQL查询:如何写出 ...

  4. delphi 从 TWebbrowse组件中获取图片

    在 delphi 中使用 TWebbrowse 组件,虽然效率不如用(idhttp之类)模拟操作效率高.但其难度低,上手快,简单粗暴有效. 从网上搜到的处理此问题的文章大多是 ctrl + c 复制到 ...

  5. Delphi中Tlist实例

    http://blog.163.com/jiandande3218@126/blog/static/74728469201132721428194/ Delphi中Tlist实例 2011-04-27 ...

  6. 第七十七篇:ref引用(在vue中引用组件实例)

    好家伙, 为方便理解, 我们先来写一个经典自增一按钮, 再加上一个count清零按钮, Left.vue组件中: <template> <div > <h1>我是L ...

  7. delphi列表视图组件(TListView)使用方法|实例

    TListView 组件以多种形式显示列表的项目,如详细资料.小图标.大图标等形式表示列表中的项目.    列表视图与用TListBox 组件实现的列表框非常相似.不同的是,列表视图可以让用户选择不同 ...

  8. Delphi中使用比较少的一些语法

    本文是为了加强记忆而写,这里写的大多数内容都是在编程的日常工作中使用频率不高的东西,但是又十分重要. ---Murphy 1,构造和析构函数: a,构造函数: 一般基于TComponent组件的派生类 ...

  9. 谈Delphi中SSL协议的应用(好多相关文章)

    摘要:本文主要介绍如何在Delphi中使用SSL协议.一共分为七个部分:(1)SSL协议是什么?(2)Delphi中如何使用SSL协议?(3)SSL客户端编程实例.(4)SSL服务端编程实例.(5)S ...

随机推荐

  1. web(七)css的语法规则、注释

    css的语法规则:特殊的css语法标识. !important:当使用多种方式设定标签样式时,设定样式渲染的应用优先权,声明在取值之后. .important { color: red !import ...

  2. 《Linux内核原理与分析》第二周作业

    反汇编一个简单的C程序 1.实验要求 使用: gcc –S –o test.s test.c -m32 命令编译成汇编代码,对汇编代码进行分析总结.其中test.c的具体内容如下: int g(int ...

  3. kvm创建新虚拟机

    安装图形化管理界面yum install virt-manager -y 安装好之后 新建虚拟机,我使用的方法是使用ISO镜像文件安装 选择镜像 设置内存 如此,一步一步走下去即可,不再截图 创建好之 ...

  4. wmv 播放器

    部分代码如下 QAction *openFile = new QAction(QIcon(QString(":/Res/open.png")), tr("打开文件&quo ...

  5. 解决ansible上传速度慢的问题

    问题: 假如有A.B.C.D....等机器,机器A为Ansible服务器,机器B.C.D...等为Ansible管理的节点服务器,A机器与其他机器都不在同一个网络,也就是A机器必须添加VPN之后才能与 ...

  6. Hanlp分词1.7版本在Spark中分布式使用记录

    新发布1.7.0版本的hanlp自然语言处理工具包差不多已经有半年时间了,最近也是一直在整理这个新版本hanlp分词工具的相关内容.不过按照当前的整理进度,还需要一段时间再给大家详细分享整理的内容.昨 ...

  7. mac os high sierra下搭建php多版本-php5.2+php5.6-nginx

    xampp的apache彻底启动不来了. php52的编译参数 ./configure --prefix=/usr/local/Cellar/php52bysk/ --with-config-file ...

  8. python 基本语句

    python 基本语句 在使用python的变量前必须给它赋值,因为python变量没有默认值. 获取用户输入值 此时需要注意:input函数的返回值为文本或字符串. 一些简单的函数 乘方 绝对值 将 ...

  9. LeetCode【100. 相同的树】

    看到这道题,第一思考是结构和节点完全相同 第一次,就没有思考null的情况 if(p.val == q.val && p.left.val == q.left.val &&am ...

  10. Linux的命令技巧

    一.使用apt-get installl 方法安装的库或者程序一般的路径如下 1.下载的软件存放位置       /var/cache/apt/archives 2.安装后软件默认位置    /usr ...