我重写了TDBGridEhExportAsXLS.WriteTitle函数,到合并单元格的时候不会写了(技术有点洼),思路也有了,请大家帮我完善一下,相信对大家都有用的。谢谢!
procedure TDBGridEhExportAsXLS.WriteTitle(ColumnsList: TColumnsEhList);
var
i, k,m: Integer;
TitleStr:String;
Function GetTitleRow:Integer;//获取表头最大层数
var
i, k,m: Integer;
MaxRow,Row:Integer;
begin
MaxRow:=1;
for i:=0 to ColumnsList.count-1 do
begin
Row:=1;
m:=0;
for j:=0 to Length(ColumnsList[i].Title.caption)-2 do
begin
if (ColumnsList[i].Title.Caption[j]='|') and ((j-m)>0) and
(ColumnsList[i].Title.Caption[j+1]<>'|') then
begin
Inc(Row);
m:=j+1;
end;
end;
if MaxRow<Row then
MaxRow:=Row;
end;
Result:=MaxRow;
end;
begin
if (DBGridEh.UseMultiTitle=false) or (GetTitleRow=1) then
begin
for i := 0 to ColumnsList.Count - 1 do
begin
WriteStringCell(ColumnsList[i].Title.Caption);
end;
end
else
begin
for i:=0 to ColumnsList.Count-1 do
begin
Frow:=0;
TitleStr:='';
m:=0;
for j:=0 to Length(ColumnsList[i].Title.caption)-2 do//写表头
begin
if (ColumnsList[i].Title.Caption[j]='|') and ((j-m)>0) and //写非最后一行表头
(ColumnsList[i].Title.Caption[j+1]<>'|') then
begin
WriteStringCell(TitleStr);
if i=ColumnsList.count-1 then
begin
Fcol:=i;
end
else
begin
Fcol:=Fcol-1;
Inc(Frow);
end;
m:=j+1;
TitleStr:='';
end
else
begin
TitleStr:=TitleStr+ColumnsList[i].Title.Caption[j];
end;
end;
Frow:=GetTitleRow-1;
TitleStr:=TitleStr+ColumnsList[i].Title.Caption[j];
WriteStringCell(TitleStr); //写最后一行表头
end;
begin
//此处为:按行从左到又合并相临的不为空的内容相同的单元格
end;
begin
//此处为:按列从下到上将内容不为空的单元格和它上面内容为空的单元格合并
end;
Fcol:=0;
Frow:=GetTitleRow;
end;
end;
procedure TDBGridEhExportAsXLS.WriteTitle(ColumnsList: TColumnsEhList);
var
i, k,m: Integer;
TitleStr:String;
Function GetTitleRow:Integer;//获取表头最大层数
var
i, k,m: Integer;
MaxRow,Row:Integer;
begin
MaxRow:=1;
for i:=0 to ColumnsList.count-1 do
begin
Row:=1;
m:=0;
for j:=0 to Length(ColumnsList[i].Title.caption)-2 do
begin
if (ColumnsList[i].Title.Caption[j]='|') and ((j-m)>0) and
(ColumnsList[i].Title.Caption[j+1]<>'|') then
begin
Inc(Row);
m:=j+1;
end;
end;
if MaxRow<Row then
MaxRow:=Row;
end;
Result:=MaxRow;
end;
begin
if (DBGridEh.UseMultiTitle=false) or (GetTitleRow=1) then
begin
for i := 0 to ColumnsList.Count - 1 do
begin
WriteStringCell(ColumnsList[i].Title.Caption);
end;
end
else
begin
for i:=0 to ColumnsList.Count-1 do
begin
Frow:=0;
TitleStr:='';
m:=0;
for j:=0 to Length(ColumnsList[i].Title.caption)-2 do//写表头
begin
if (ColumnsList[i].Title.Caption[j]='|') and ((j-m)>0) and //写非最后一行表头
(ColumnsList[i].Title.Caption[j+1]<>'|') then
begin
WriteStringCell(TitleStr);
if i=ColumnsList.count-1 then
begin
Fcol:=i;
end
else
begin
Fcol:=Fcol-1;
Inc(Frow);
end;
m:=j+1;
TitleStr:='';
end
else
begin
TitleStr:=TitleStr+ColumnsList[i].Title.Caption[j];
end;
end;
Frow:=GetTitleRow-1;
TitleStr:=TitleStr+ColumnsList[i].Title.Caption[j];
WriteStringCell(TitleStr); //写最后一行表头
end;
begin
//此处为:按行从左到又合并相临的不为空的内容相同的单元格
end;
begin
//此处为:按列从下到上将内容不为空的单元格和它上面内容为空的单元格合并
end;
Fcol:=0;
Frow:=GetTitleRow;
end;
end;
解决方案 »
- 关于delphi封装的http,ftp,udp,tcp等协议的使用问题
- 关于Treeview的一个问题.
- 如何快速检测对方机算机的IP和某个端口是否打开
- 我用的是delphi5,所以没有idsmtp控件,我可以下载一个吗?
- 请问如何给一个程序发送组合键消息,比如ctrl+g
- ,我在写一个网吧操作监视程序,把用户使用的任意窗体包括浏览器的内容即时输入到Form1.Memo1里处理,如何实现?
- Easy Question
- 如何从abcde.db中取出文件名abcde,而不要扩展名呢?
- 刚学DELPHI,最简单的问题,关于工具栏
- 看一下我的程序哪里有错?
- 我想请教一下各位大俠,希望各位帮一下忙
- 应该还是个挺容易的问题吧?帮帮忙啦,挺急的~
这个你参考下 for inti:=0 to length(columnNo)-1 do
begin s:=DBGridEh1.Columns[columnNo[inti]].Title.Caption ;
i:=pos('|',s);
if i<>0 then
begin
StrT1:=copy(s,1,i-1);
strT2:=copy(s,i+1,length(s)-i);
//±È½ÏºóÒ»¸öÊý¾Ý if inti<length(columnNo)-1 then
begin
s:=DBGridEh1.Columns[columnNo[inti+1]].Title.Caption ;
i:=pos('|',s);
StrT3:=copy(s,1,i-1);
strT4:=copy(s,i+1,length(s)-i);
end; if StrT1=strT3 then
begin
setlength(arrayA,length(arrayA)+1);
arrayA[high(arrayA)]:=StrT2;
continue;
end
else
begin
setlength(arrayA,length(arrayA)+1);
arrayA[high(arrayA)]:=StrT2;
if length(arrayA)>=1 then
begin
//±êÌâ1
if (inti-length(arrayA)+1)>=26 then
begin
intc:=(inti+intx-length(arrayA)) div 26;
intk:=(inti-length(arrayA)+1) mod 26;
crstr:=chr(65+intc-1)+chr(65+inti-length(arrayA)+1-26*intc)+'3'+':'+chr(65+intc-1)+chr(65+inti-26*intc)+'3';
end
else
crstr:=chr(65+inti-length(arrayA)+1)+'3'+':'+chr(65+inti)+'3'; // crstr:='A1:K1';
FillRectText(strT1 ,crstr);
for intx:=1 to length(arrayA) do
begin
//±êÌâ2
if (inti+intx-length(arrayA))>=26 then
begin
intc:=(inti+intx-length(arrayA)) div 26;
intk:=(inti+intx-length(arrayA)) mod 26;
// crstr:=chr(65+intk)+chr(65+inti+intx-length(arrayA))+'4'+':'+chr(65+inti)+'4';
crstr:=chr(65+intc-1)+chr(65+inti+intx-length(arrayA)-26*intc)+'4';
end
else
crstr:=chr(65+inti+intx-length(arrayA))+'4'; FillRectText(arrayA[intx-1] ,crstr);
end;
end ;
setlength(arrayA,0);
end;
end
else
begin
stra:=DBGridEh1.Columns[columnNo[inti]].Title.Caption ;
crstr:=chr(65+inti)+'3';
FillRectText(stra,crstr);
end;
end ;
if length(arrayA)>=1 then
begin
//±êÌâ1
if (inti-length(arrayA)+1)>=26 then
begin
intc:=(inti-length(arrayA)) div 26;
intk:=(inti-length(arrayA)+1) mod 26;
crstr:=chr(65+intc-1)+chr(65+inti-length(arrayA)-26*intc)+'3'+':'+chr(65++intc-1)+chr(65+inti-1-26*intc)+'3';
end
else
crstr:=chr(65+inti-length(arrayA))+'3'+':'+chr(65+inti-1)+'3';
// crstr:='A1:K1';
FillRectText(strT1 ,crstr);
for intx:=1 to length(arrayA) do
begin if (inti+intx-length(arrayA))>=26 then
begin
intc:=(inti+intx-length(arrayA)) div 26;
intk:=(inti+intx-length(arrayA)) mod 26;
// crstr:=chr(65+intk)+chr(65+inti+intx-length(arrayA))+'4'+':'+chr(65+inti)+'4';
crstr:=chr(65+intc-1)+chr(65+inti+intx-length(arrayA)-1-26*intc)+'4';
end
else
crstr:=chr(65+inti+intx-length(arrayA)-1)+'4';
FillRectText(arrayA[intx-1] ,crstr);
end;
end ;
setlength(arrayA,0); dbgrideh1.DataSource.DataSet.First;
for inti:=0 to dbgrideh1.DataSource.DataSet.RecordCount-1 do
begin for intx:=low(columnNo) to high(columnNo) do
begin
stra:=DBGridEh1.Columns[columnNo[intx]].FieldName;
s:=dbgrideh1.DataSource.DataSet.fieldbyname(stra).asstring;
if intx>=26 then
begin
intc:=(inti+intx-length(arrayA)) div 26;
crstr:=chr(65+intc-1)+chr(65+intx-26*intc)+inttostr(5+inti);
end
else
crstr:=chr(65+intx)+inttostr(5+inti);
if intx=0 then
s:=''''+s;
FillRectText(s ,crstr); end;
dbgrideh1.DataSource.DataSet.next; //-------------------------------------
{ for inttmp:=0 to length(columnNo)-1 do
begin s:=DBGridEh1.f
FillRectText(s ,crstr);
end; } //-------------------------------------
end;
Begin
CapStr:=trim(exApp.Cells[Row,1].value);
Col1:=2;
Col2:=FldCount;
For Col1:=2 to Col2 Do
begin
NewCapStr:=trim(exApp.Cells[Row,Col1].value);
if (NewCapStr=CapStr) then
Begin
Cell1:=exApp.Cells.Item[Row,Col1-1];
Cell2:=exApp.Cells.Item[Row,Col1];
exApp.Cells[Row,Col1].value:='';
exApp.Range[Cell1,Cell2].Merge(True);
end
else
begin
CapStr:=NewCapStr;
end;
end;
哪们老大给发份完整的啊
[email protected]感激不尽!