第三方组件: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. i3wm 入门

    安装 所用Linux版本为kali-rolling,直接安装 apt install i3 设置为xinit的启动对像 修改 ~/.xserverrc #!/bin/sh exec /usr/bin/ ...

  2. latex之矩阵表示

    $ \begin{matrix} 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1 \end{matrix}\quad \begin{ ...

  3. OneStopEnglish corpus: A new corpus for automatic readability assessment and text simplification-paper

    这篇论文的related work非常详尽地介绍了各种readability的语料 abstract这个paper描述了onestopengilish这个三个level的文本语料的收集和整理,阐述了再 ...

  4. maven整合ssh框架笔记

    具体工程会上传文件sshpro <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:x ...

  5. 【自动化测试:笔记一】adb命令

    1.查看当前连接的设备数 adb devices 2.连接设备 adb connect <设备名> 3.安装卸载app adb install packagesname adb unins ...

  6. PythonStudy——第一阶段性测试

    1.Python解释器,在2.x和3.x上分别采用的是什么默认编码8 2.定义字符串变量时,单引号,双引号,三引号什么区别? 3.编程语言可以分为哪三类,特点都是什么 4.定义一个变量有三个特性, 5 ...

  7. PythonStudy——编程基础 Python Primary

    1.什么是编程语言 语言:  一个事物与另外一个事物沟通的介质 .编程语言是程序员与计算机沟通的介质. 编程: 将人类内识别的语言转化为机器能识别的指令,这种过程就叫做编程. 注:最终这些指令会被转化 ...

  8. 使用fpm 软件包打包

    安装 sudo gem install --no-ri --no-rdoc fpm 简单使用 一个 redis的简单demo % ls src/redis-server redis.conf src/ ...

  9. 集合总结二(LinkedList的实现原理)

    一.概述 先来看看源码中的这一段注释,我们先尝试从中提取一些信息: Doubly-linked list implementation of the List and Deque interfaces ...

  10. js 函数问题

    replace() is not a function 1,情景描述:做项目的时候想把内容的某些字符给替换成另外一些字符 2,replace用法:replace() 方法用于在字符串中用一些字符替换另 ...