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

更新时间:2023-08-11 21:31:51 阅读: 评论:0

在delphi中XLSReadWriteII.组件的应⽤实例(1)第三⽅组件:XLSReadWriteII.v.5.20.67_XE3
实例源码如下:
unit Unit1;
米歇尔 奥巴马interface
us
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Class, 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
us strUtils,
英语论文网站
XLSDbRead5, Xc12Manager5, Xc12Utils5, XLSUtils5,
Xc12DataStyleSheet5, XLSFormattedObj5, Xc12DataWorksheet5;
{$R *.dfm}
type
TDelFlags = t of (dfDelBefore, dfDelAfter);
function Delstr(var ms: String; endstr: String; Flags: TDelFlags;
blf: Boolean = True): String;
var
l: Integer;
begin
l := length(endstr);
if dfDelBefore in Flags then
begin
if blf then
begin
Result := copy(ms, 1, pos(endstr, ms) + l - 1);
Delete(ms, 1, pos(endstr, ms) + l - 1);
end
el
begin
Result := copy(ms, 1, pos(endstr, ms) - 1);
lineh
Delete(ms, 1, pos(endstr, ms) - 1);
end;
end
el
begin
if blf then
begin
Result := copy(ms, pos(endstr, ms), length(ms));
Delete(ms, pos(endstr, ms), length(ms));
end
el
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
el if (element^ = Chr(0)) and (pattern^ <> Chr(0)) then
Result := Fal
el if element^ = Chr(0) then
Result := True
el
begin
ca pattern^ of
'*':
if MatchPattern(element, @pattern[1]) then
Result := True
el
Result := MatchPattern(@element[1], pattern);
'?':
Result := MatchPattern(@element[1], @pattern[1]);
el
if element^ = pattern^ then
Result := MatchPattern(@element[1], @pattern[1])
el
Result := Fal;
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
el //找到⽂件
begin
{拷贝所有类型的⽂件}
if Matchstrings(LowerCa(FileRec.Name), SearchFileType) then
begin
List.Add(Sour + FileRec.Name);
end; {拷贝所有类型的⽂件}
end;
until FindNext(FileRec) <> 0;
FindClo(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:=fal;  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 UpperCa(ExtractFileExt(AFullXLSXFilePath))='.XLSX' then      XLS3.Version:=xvExcel2007
el
XLS3.Version:=xvExcel97;
//  XLS3.DirectWrite:=fal;
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;
carin
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
el
begin
eNum:=posEx('□',aline,kNum);
if eNum-eNum=1 then
begin
kNum:=eNum;
dec(pNnum);
end
el
invalidargumentbegin
kNum:=eNum;
sQuezi:=sQuezi+slinebreak+'('+inttostr(pNnum)+')'+copy(aline,kNum-6,20);                            end;
end;
end
el
begin
if sQuezi='' then
sQuezi:='('+inttostr(pNnum)+')'+copy(aline,kNum-6,20)
el
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:=fal;
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:=fal;
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:='⽣成清单';
wanna什么意思end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Clear ;
edit2.Clear ;
edit1.Text:='C:\Urs\Administrator\Desktop\test';
edit2.Text:='C:\Urs\Administrator\Desktop\test\xx.xls';
end;
end.

本文发布于:2023-08-11 21:31:51,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/194042.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:类型   实例   报名   培训班   格式   口译   北京
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图