大哥,我要打印StringGrid能打点一下吗? 大哥,我要打印StringGrid能打点一下吗?和显示的一样。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转载别人的代码,看看是否对你有帮助打印StringGrid,当然,是我作组件中碰到的问题。这个StringGrid是完全独立的,不用任何数据库,不用DataSource,代码。procedure TForm1.SpeedButton11Click(Sender: TObject);Var Index_R ,ALeft: Integer; Index : Integer;begin StringGrid_File('D:\AAA.TXT'); if Not LinkTextFile then begin ShowMessage('失败'); Exit; end; // QuickRep1.DataSet := ADOTable1; Index_R := ReSize(StringGrid1.Width); ALeft := 13; Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[0].Width,20, HeaderControl1.Sections[0].Text,taLeftJustify); with Create_QRDBText(DetailBand1,ALeft,8,StringGrid1.ColWidths[0],20, StringGrid1.Font,taLeftJustify) do begin DataSet := ADOTable1; DataField := ADOTable1.Fields[0].DisplayName; end; ALeft := ALeft + StringGrid1.ColWidths[0] * Index_R + Index_R; For Index := 1 to ADOTable1.FieldCount - 1 do begin Create_VLine(TitleBand1,ALeft - 13,16,1,40); Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[Index].Width,20, HeaderControl1.Sections[Index].Text,taLeftJustify); Create_VLine(DetailBand1,ALeft - 13,-1,1,31); with Create_QRDBText(DetailBand1,ALeft ,8,StringGrid1.ColWidths[Index] * Index_R,20, StringGrid1.Font,taLeftJustify) do begin DataSet := ADOTable1; DataField := ADOTable1.Fields[Index].DisplayName; end; ALeft := ALeft + StringGrid1.ColWidths[Index] * Index_R + Index_R; end; QuickRep1.Preview;end;function TForm1.ReSize(AGridWidth: Integer): Integer;begin Result := Trunc(718 / AGridWidth);end;function TForm1.StringGrid_File(AFileName: String): Boolean;var StrValue : String; Index : Integer; ACol , ARow : Integer; AFileValue : System.TextFile;begin StrValue := ''; Try AssignFile(AFileValue , AFileName); ReWrite(AFileValue); StrValue := HeaderControl1.Sections[0].Text; For Index := 1 to HeaderControl1.Sections.Count - 1 do StrValue := StrValue + ',' + HeaderControl1.Sections[Index].Text; Writeln(AFileValue,StrValue); StrValue := ''; For ARow := 0 To StringGrid1.RowCount - 1 do begin StrValue := ''; StrValue := StringGrid1.Cells[0,ARow]; For ACol := 1 To StringGrid1.ColCount - 1 do begin StrValue := StrValue + ', ' + StringGrid1.Cells[ACol,ARow]; end; Writeln(AFileValue,StrValue); end; Finally CloseFile(AFileValue); end;end;function TForm1.LinkTextFile: Boolean;begin Result := False; with ADOTable1 do begin {ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source= D:\;Extended Properties=Text;' + 'Persist Security Info=False'; TableName := 'AAA#TXT'; Open; } if Active then Result := True; end;end;function TForm1.Create_QRDBText(Sender: TWinControl; ALeft, ATop, AWidth, AHight: Integer; AFont: TFont; AAlignMent: TAlignment): TQRDBText;var AQRDBText : TQRDBText;begin AQRDBText := TQRDBText.Create(Nil); with AQRDBText do begin Parent := Sender; Left := ALeft; Top := ATop; Width := AWidth; Height := AHight; AlignMent := AAlignMent; Font.Assign(AFont); end; Result := AQRDBText;end;function TForm1.Create_VLine(Sender: TWinControl; ALeft, ATop, AWidth, AHight: Integer): TQRShape;var AQRShapeV : TQRShape;begin AQRShapeV := TQRShape.Create(Nil); with AQRShapeV do begin Parent := Sender; Left := ALeft; Top := ATop; Width := AWidth; Height := AHight; end; Result := AQRShapeV;end;procedure TForm1.Create_Title(Sender: TWinControl; ALeft, ATop, AWidth, AHight: Integer; ACaption: String; AAlignMent: TAlignment);var AQRLabel : TQRLabel;begin AQRLabel := TQRLabel.Create(Nil); with AQRLabel do begin Parent := Sender; Left := ALeft; Top := ATop; Width := AWidth; AlignMent := AAlignMent; Caption := ACaption; end;end; 用我的控件, 有打印预览!http://www.csdn.net/cnshare/soft/15/15471.shtm 有关indy的TCP服务器与java开发的客户端通讯的问题. 郁闷,动态创建的WebBrowser为什么它的宽和高更改不了?解决马上给分... panel控件可以作成换肤的么? 请教一数据库插入问题 5G商业源码FTP会员制超值下载!!! delphi7的报表组件在哪? 谁能提供DELPHI自带的DEMOS的所有例子的相关资料?? ***怎样画一个角出来??一有答案,马上给分。 如果我要让最大化按钮不可见(不是把最大化变成灰度),应该怎样做? 对Jpg文件的不兼容 求助 DBGRID 的问题 (当单元格得到焦点时怎么实现combo的效果) 基础问题
procedure TForm1.SpeedButton11Click(Sender: TObject);
Var
Index_R ,ALeft: Integer;
Index : Integer;
begin
StringGrid_File('D:\AAA.TXT');
if Not LinkTextFile then
begin
ShowMessage('失败');
Exit;
end;
//
QuickRep1.DataSet := ADOTable1;
Index_R := ReSize(StringGrid1.Width);
ALeft := 13;
Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[0].Width,20,
HeaderControl1.Sections[0].Text,taLeftJustify);
with Create_QRDBText(DetailBand1,ALeft,8,StringGrid1.ColWidths[0],20,
StringGrid1.Font,taLeftJustify) do
begin
DataSet := ADOTable1;
DataField := ADOTable1.Fields[0].DisplayName;
end;
ALeft := ALeft + StringGrid1.ColWidths[0] * Index_R + Index_R;
For Index := 1 to ADOTable1.FieldCount - 1 do
begin
Create_VLine(TitleBand1,ALeft - 13,16,1,40);
Create_Title(TitleBand1,ALeft,24,HeaderControl1.Sections.Items[Index].Width,20,
HeaderControl1.Sections[Index].Text,taLeftJustify);
Create_VLine(DetailBand1,ALeft - 13,-1,1,31);
with Create_QRDBText(DetailBand1,ALeft ,8,StringGrid1.ColWidths[Index] * Index_R,20,
StringGrid1.Font,taLeftJustify) do
begin
DataSet := ADOTable1;
DataField := ADOTable1.Fields[Index].DisplayName;
end;
ALeft := ALeft + StringGrid1.ColWidths[Index] * Index_R + Index_R;
end;
QuickRep1.Preview;
end;function TForm1.ReSize(AGridWidth: Integer): Integer;
begin
Result := Trunc(718 / AGridWidth);
end;function TForm1.StringGrid_File(AFileName: String): Boolean;
var
StrValue : String;
Index : Integer;
ACol , ARow : Integer;
AFileValue : System.TextFile;
begin
StrValue := '';
Try
AssignFile(AFileValue , AFileName);
ReWrite(AFileValue);
StrValue := HeaderControl1.Sections[0].Text;
For Index := 1 to HeaderControl1.Sections.Count - 1 do
StrValue := StrValue + ',' + HeaderControl1.Sections[Index].Text;
Writeln(AFileValue,StrValue);
StrValue := '';
For ARow := 0 To StringGrid1.RowCount - 1 do
begin
StrValue := '';
StrValue := StringGrid1.Cells[0,ARow];
For ACol := 1 To StringGrid1.ColCount - 1 do
begin
StrValue := StrValue + ', ' + StringGrid1.Cells[ACol,ARow];
end;
Writeln(AFileValue,StrValue);
end;
Finally
CloseFile(AFileValue);
end;
end;function TForm1.LinkTextFile: Boolean;
begin
Result := False;
with ADOTable1 do
begin
{ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;' +
'Data Source= D:\;Extended Properties=Text;' +
'Persist Security Info=False';
TableName := 'AAA#TXT';
Open; }
if Active then
Result := True;
end;
end;function TForm1.Create_QRDBText(Sender: TWinControl; ALeft, ATop, AWidth,
AHight: Integer; AFont: TFont; AAlignMent: TAlignment): TQRDBText;
var
AQRDBText : TQRDBText;
begin
AQRDBText := TQRDBText.Create(Nil);
with AQRDBText do
begin
Parent := Sender;
Left := ALeft;
Top := ATop;
Width := AWidth;
Height := AHight;
AlignMent := AAlignMent;
Font.Assign(AFont);
end;
Result := AQRDBText;
end;function TForm1.Create_VLine(Sender: TWinControl; ALeft, ATop, AWidth,
AHight: Integer): TQRShape;
var
AQRShapeV : TQRShape;
begin
AQRShapeV := TQRShape.Create(Nil);
with AQRShapeV do
begin
Parent := Sender;
Left := ALeft;
Top := ATop;
Width := AWidth;
Height := AHight;
end;
Result := AQRShapeV;
end;procedure TForm1.Create_Title(Sender: TWinControl; ALeft, ATop, AWidth,
AHight: Integer; ACaption: String; AAlignMent: TAlignment);
var
AQRLabel : TQRLabel;
begin
AQRLabel := TQRLabel.Create(Nil);
with AQRLabel do
begin
Parent := Sender;
Left := ALeft;
Top := ATop;
Width := AWidth;
AlignMent := AAlignMent;
Caption := ACaption;
end;
end;
http://www.csdn.net/cnshare/soft/15/15471.shtm