📄 wwexport.pas
字号:
gridBrush := Grid.Canvas.Brush;
GridBrush.Color:=TwwDBGrid(Grid).TitleColor;
gridTitleALignment:=Grid.TitleAlignment;
if esoDynamicColors in self.Options then
Grid.DoCalcTitleAttributes(Grid.DataLink.Fields[i].FieldName, gridFont, gridBrush, gridTitleAlignment);
fonttag := AddToSYLKFontList(gridFont,SYLKFontList);
if (grid.Columns[getdbcol(Grid,i+grid.xIndicatorOffset)].GroupName = '') then begin
tempdisplaylabel := strReplaceCharWithStr(grid.Columns[getdbcol(Grid,i+grid.xIndicatorOffset)].DisplayLabel,';',';;');
tempdisplaylabel := getdisplaylabelforline(tempdisplaylabel,j+1);
rowstr := rowstr+'F;SLR';
if j=0 then rowstr := rowstr+'T';
if (j=Grid.TitleLines-1) then rowstr := rowstr+'B';
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
rowstr := rowstr+'M'+fonttag+';FG0'+GetSYLKAlignment(gridTitleALignment)+';Y'+inttostr(j+1)+';X'+Inttostr(exportfieldcount+1)+wwCRLF;
if tempdisplaylabel <> '' then
rowstr := rowstr+'C;K"'+ tempdisplaylabel+ '"'+wwCRLF;
inc(exportfieldcount);
end
else begin
if j<(grid.titlelines div 2) then begin
tempdisplaylabel := strReplaceCharWithStr(grid.Columns[getdbcol(Grid,i+grid.xIndicatorOffset)].GroupName,';',';;');
tempdisplaylabel := getdisplaylabelforline(tempdisplaylabel,j+1);
rowstr := rowstr+'F;SL';
if j+1 >= (grid.titlelines div 2) then rowstr := rowstr+'B';
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
rowstr := rowstr+'M0;FG0C;Y'+inttostr(j+1)+';X'+Inttostr(exportfieldcount+1)+wwCRLF;
// rowstr := rowstr+'F;SLBRM'+fonttag+';FG0'+GetSYLKAlignment(gridTitleALignment)+';Y2;X'+Inttostr(i+1+recoffset)+wwCRLF;
rowstr := rowstr+'C;K"'+ tempdisplaylabel+ '"'+wwCRLF;
groupColCount := 0;
//!!11/29/2001
for k:=startcol to endcol do
if exportFieldList[k-1] = 'T' then inc(groupColcount);
for k:=i+1 to i+groupcolcount-1 do begin
if exportFieldList[k] = 'T' then
begin
rowstr := rowstr+'F;S';
if (j+1>=grid.titlelines div 2) then rowstr := rowstr+'B';
rowstr := rowstr+'M0;FG0C;X'+Inttostr(k+1+recoffset)+wwCRLF;
rowstr := rowstr+'C;K""'+wwCRLF;
end;
end;
inc(i,endcol-startcol);
inc(exportfieldcount);
end
else begin
tempdisplaylabel := strReplaceCharWithStr(grid.Columns[getdbcol(Grid,i+grid.xIndicatorOffset)].DisplayLabel,';',';;');
tempdisplaylabel := getdisplaylabelforline(tempdisplaylabel,j+1-(grid.titlelines div 2));
rowstr := rowstr+'F;SLR';
if (j-1)<(grid.titlelines div 2) then rowstr := rowstr+'T';
if (j=Grid.TitleLines-1) then rowstr := rowstr+'B';
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
rowstr := rowstr+'M'+fonttag+';FG0'+GetSYLKAlignment(gridTitleALignment)+';Y'+inttostr(j+1)+';X'+Inttostr(exportfieldcount+1)+wwCRLF;
if tempdisplaylabel <> '' then
rowstr := rowstr+'C;K"'+ tempdisplaylabel+ '"'+wwCRLF;
inc(exportfieldcount);
end;
end;
end;
inc(i);
end
else begin //First Row of a Group Cell. Add tag and get next cell
grid.GroupNameCellRect(i+grid.xIndicatorOffset,0,startcol,endcol,false);
groupColCount := 0;
for k:=startcol to endcol do begin
if exportFieldList[k-1] = 'T' then
inc(groupColcount);
end;
if groupcolCount > 0 then begin
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
rowstr := rowstr+'F;SLTM0;FG0C;Y1;X'+Inttostr(exportfieldcount+1)+wwCRLF;
inc(exportfieldcount);
tempdisplaylabel := strReplaceCharWithStr(grid.Columns[getdbcol(Grid,i+grid.xIndicatorOffset)].GroupName,';',';;');
tempdisplaylabel := getdisplaylabelforline(tempdisplaylabel,j+1);
rowstr := rowstr+'C;K"'+ tempdisplaylabel + '"'+wwCRLF;
for k:=i+1 to i+groupcolcount-1 do begin
if exportFieldList[k] = 'T' then begin
rowstr := rowstr+'F;STM0;FG0C;X'+Inttostr(k+1+recoffset)+wwCRLF;
rowstr := rowstr+'C;K""'+wwCRLF;
inc(exportfieldcount);
end;
end;
// groupassigned := True;
end;
inc(i,endcol-startcol+1);
end;
end;
//if not groupassigned then break;
end;
end;
result := rowstr+wwCRLF;
end;
function WriteSYLKDataRow:String;
var i:integer;
RowStr,fonttag,tempstr:String;
recoffset:integer;
gridfont:TFont;
gridbrush:TBrush;
exportfieldcount:integer;
Pos1,rownumberoffset:integer; //6/13/2001-Added to handle case where header is not shown in file.
AControlType, Parameters: wwSmallString;
customedit:TWinControl;
controlname:String;
//SaveDecimal:char;
begin
with Grid do begin
rowstr := '';
recoffset :=0;
rownumberoffset := 0;
//9/26/2001-Only increment the rownumberoffset by as many rows that are in the header.
if esoShowHeader in self.Options then
rownumberoffset := TitleLines;
if esoShowRecordNo in self.Options then begin
if (TitleFont.Name <> Font.Name) or (TitleFont.Size <> Font.Size) or
((fsBold in TitleFont.Style) and not (fsBold in Font.Style)) or
(not (fsBold in TitleFont.Style) and (fsBold in Font.Style)) or
((fsItalic in TitleFont.Style) and not (fsItalic in Font.Style)) or
(not (fsItalic in TitleFont.Style) and (fsItalic in Font.Style)) or
((fsUnderline in TitleFont.Style) and not (fsUnderline in Font.Style)) or
(not (fsUnderline in TitleFont.Style) and (fsUnderline in Font.Style)) or
((fsStrikeOut in TitleFont.Style) and not (fsStrikeOut in Font.Style)) or
(not (fsStrikeOut in TitleFont.Style) and (fsStrikeOut in Font.Style)) then
rowstr := rowstr+'F;SLRTBM1;FG0L;Y'+inttostr(curRowCount+rownumberoffset)+';X1'+wwCRLF
else rowstr := rowstr+'F;SLRTBM0;FG0L;Y'+inttostr(curRowCount+rownumberoffset)+';X1'+wwCRLF;
rowstr := rowstr + 'C;K'+IntToStr(curRowCount)+wwCRLF;
recoffset :=1;
end;
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
exportfieldcount:=recoffset;
for i:=0 to exportFieldList.Count-1 do begin
if (exportFieldList[i] = 'T') then begin
inc(exportfieldcount);
gridFont := Grid.Canvas.Font;
gridFont.assign(Font);
gridBrush := Grid.Canvas.Brush;
GridBrush.Color:=Color;
if esoDynamicColors in self.Options then
Grid.DoCalcCellColors(DataLink.Fields[i], [], False, gridFont, gridBrush);
fonttag := AddToSYLKFontList(gridFont,SYLKFontList);
//9/26/2001-Specify the associated format based on field and datatype.
// 10/01/2001 -PYW - Use current numbered exported field instead of fieldnumber
case Grid.Datalink.Fields[i].datatype of
{$ifdef wwDelphi6Up}
ftTimeStamp, ftFmtBCD,
{$endif}
ftBCD, ftFloat,ftDate,ftTime,ftDateTime,ftCurrency:
rowstr := rowstr+'F;P'+SYLKFormatIndex[i]+';SLTRBM'+fonttag+';FG0'+GetSYLKAlignment(Grid.Datalink.Fields[i].alignment)+';Y'+inttostr(curRowCount+rownumberoffset)+';X'+inttostr(exportfieldcount)+wwCRLF;
else
rowstr := rowstr+'F;SLTRBM'+fonttag+';FG0'+GetSYLKAlignment(Grid.Datalink.Fields[i].alignment)+';Y'+inttostr(curRowCount+rownumberoffset)+';X'+inttostr(exportfieldcount)+wwCRLF;
end;
tempstr := strReplaceCharWithStr(GetFieldValue(i),';',';;');
if not Grid.DataLink.Fields[i].IsNull then
case Grid.Datalink.Fields[i].datatype of
ftBoolean:
begin
if Grid.DataLink.Fields[i].asBoolean then
tempstr := 'TRUE'
else tempstr := 'FALSE';
tempstr := 'C;K'+AddQuotes(tempstr)+wwCRLF;
end;
ftLargeInt,ftSmallInt,ftWord,ftInteger:
begin
//2/1/2002 - PYW - Added code to handle special controls in grid.
GetControlInfo(Datalink.Fields[i].FieldName, AControlType, Parameters);
if (AControlType = 'CustomEdit') then begin
Pos1:= 1;
controlname:= strGetToken(Parameters, ';', Pos1);
customEdit:= GetComponent(controlname);
if (CustomEdit is TwwDBComboBox) then
begin
if (TwwDBComboBox(CustomEdit).MapList) and
(esoAddControls in self.Options) then
tempstr := 'C;K'+AddQuotes(tempstr)+wwCRLF
else
tempstr := 'C;K'+IntToStr(Grid.DataLink.Fields[i].asInteger)+wwCRLF;
end
else if (CustomEdit is TwwRadioGroup) or (CustomEdit is TwwCheckBox) then begin
if esoAddControls in self.Options then begin
if CustomEdit is TwwCheckBox then begin
if Grid.DataLink.Fields[i].asInteger = 1 then
tempstr := 'C;K'+AddQuotes(TwwCustomCheckBox(CustomEdit).DisplayValueChecked)+wwCRLF
else
tempstr := 'C;K'+AddQuotes(TwwCustomCheckBox(CustomEdit).DisplayValueUnchecked)+wwCRLF;
end
else tempstr := 'C;K'+AddQuotes(tempstr)+wwCRLF
end
else
tempstr := 'C;K'+IntToStr(Grid.DataLink.Fields[i].asInteger)+wwCRLF;
end
else tempstr := 'C;K'+tempstr+wwCRLF;
end
else tempstr := 'C;K'+tempstr+wwCRLF;
end;
//9/26/2001-Added handling of the following additional data types.
// ftfloat,ftCurrency: tempstr := 'C;K'+FloatToStr(Grid.DataLink.Fields[i].asFloat)+wwCRLF;
{$ifdef wwDelphi6Up}
ftFmtBCD,
{$endif}
ftBCD,ftfloat,ftCurrency: begin
//3/13/2002-PYW-Make sure the SYLK format is stored with decimals
tempstr := 'C;K'+FloatToStr(Grid.DataLink.Fields[i].asFloat)+wwCRLF;
if DecimalSeparator <> '.' then
tempstr := ReplaceStrWithStr(tempstr,DecimalSeparator,'.');
end;
ftDate: tempstr := 'C;K'+IntToStr(Trunc(Grid.DataLink.Fields[i].asDateTime))+wwCRLF;
ftTime: begin
tempstr := 'C;K'+FloatToStr(Frac(Grid.DataLink.Fields[i].asDateTime))+wwCRLF;
if DecimalSeparator <> '.' then
tempstr := ReplaceStrWithStr(tempstr,DecimalSeparator,'.');
end;
{$ifdef wwDelphi6Up}
ftTimeStamp,
{$endif}
ftDateTime: begin
tempstr := 'C;K'+FloatToStr(Grid.DataLink.Fields[i].asFloat)+wwCRLF;
if DecimalSeparator <> '.' then
tempstr := ReplaceStrWithStr(tempstr,DecimalSeparator,'.');
end;
else
//SYLK does not like #13 and #10 carriage return line feed characters in string.
//Replace them with spaces.
tempstr := ReplaceStrWithStr(tempstr,#13#10,' ');
// tempstr := strReplaceCharWithStr(tempstr,#10,' ');
//Then copy the 1st 255 characters as SYLK does not like cells longer than 255.
tempstr := Copy(tempstr,1,255);
//Add SYLK Data tags.
if tempstr = '' then tempstr := 'C;K""'+wwCRLF
else tempstr := 'C;K'+AddQuotes(tempstr)+wwCRLF;
end
else tempstr := 'C;K""'+wwCRLF;
rowstr := rowstr + tempstr;
end;
end;
result := rowstr;
end;
end;
function savetostringfirst:boolean;
begin
result := False;
if esoClipboard in self.Options then begin
result := True;
end;
if ExportType = wwgetSYLK then result := True;
end;
procedure SetSYLKToClipboard;
Var
MemHandle: THandle;
begin
with clipboard do begin
MemHandle := GlobalAlloc( GHND or GMEM_SHARE, Length(totalstr)+1 );
If MemHandle <> 0 Then Begin
StrCopy( GlobalLock( MemHandle ), PChar(totalstr));//memstring );
GlobalUnlock( MemHandle );
Open;
try
AsText := totalstr;
// showmessage(totalstr);
SetAsHandle( CF_SYLK, MemHandle );
finally
Close;
end;
End
Else
MessageDlg('Global Alloc failed!', mtError, [mbOK], 0 );
end;
end;
procedure SetHTMLToClipboard;
Var
MemHandle: THandle;
CF_HTML:LONGINT;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -