在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 ...
随机推荐
- JAVA将汉字转换为全拼以及返回中文的首字母,将字符串转移为ASCII码
import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseT ...
- nf_conntrack
How to Fix Nf_conntrack Table Full Dropping Packet Linux CentOS PacketLoss 2 minutes to read (234 w ...
- 跨源资源共享(CORS)概念、实现(用Spring)、起源介绍
本文内容引用自: https://howtodoinjava.com/spring5/webmvc/spring-mvc-cors-configuration/ https://developer.m ...
- activiti学习第一天
公司项目组在考虑工作流,首选了activiti,首先我们要明确为什么要使用activiti,有什么好处. 在工作中有些项目会用到工作流,如果简单的项目,我们就无需使用类似activiti.jbpm等工 ...
- ubuntu deb pacakge 开发
安装构建工具 apt-get install pbuilder 推荐安装 sudo apt-get install build-essential autoconf automake \ autoto ...
- JS 格式化日期时间
方法一: // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1 ...
- 记账本NABCD分析
学生记账本NABCD分析 N(Need,需求) 随着我们进入大学开始逐步的扩大自己的消费水平,而我们每天无法准确的记住一笔一笔的消费记录.常常,每一个月末时我们在宿舍楼道听到不少学生抱怨这个月怎么花钱 ...
- CMake for MFC example
cmake_minimum_required(VERSION 2.8) add_definitions(-D_AFXDLL) set(CMAKE_MFC_FLAG 2) set(SRCS MFCApp ...
- php 字符串固定长度,不够补充其他字符串
<?php $input = '456'; $var= str_pad($input,5,10,STR_PAD_LEFT); w3school手冊:http://www.w3school.com ...
- NumPy-快速处理数据--ndarray对象--数组的创建和存取
本文摘自<用Python做科学计算>,版权归原作者所有. NumPy为Python提供了快速的多维数组处理的能力,而SciPy则在NumPy基础上添加了众多的科学计算所需的各种工具包,有了 ...