Szukałem po sieci jak otworzyć/zapisać plik ze StringGridu i jak wydrukowac zawartość StringGrida poprzez Printersetupdialog.
Znalazłem zapisywanie poprzez Savedialog, ale odziwo nie moge znaleźć otwieranie pliku poprzez Opendialog do Stringgrida.
Znalazłem prockę do drukowania poprzez printers, ale mnie to nie interesuje, tylko poprzez Printersetupdialog. Nie wiem co już robić. Czy ktoś życzliwy mógłby podać na Opendialog i Printersetupdialog kodziki?
Bardzo bym prosił, sieć przeszukałem za tymi kodami i nie znalazłem.
Oto zdobyte przeze mnie kody dotychczas:
Do zapisywania ze Stringgrid:
procedure TForm1.Button2Click(Sender: TObject);
//begin
//SaveStringGrid(StringGrid1, 'c:\temp.txt');
var
i,j:Integer;
plik : TextFile;
begin
if SaveDialog1.Execute then
begin
AssignFile(plik ,SaveDialog1.FileName );
Rewrite(plik);
for i:=0 to StringGrid1.ColCount-1 do
for j:=0 to StringGrid1.RowCount-1 do
begin
if i=StringGrid1.ColCount-1 then Write(plik, StringGrid1.Cells[i,j])
else Writeln(plik,StringGrid1.Cells[i,j]);
end;
end;
Flush (plik);
CloseFile(plik);
end;
Do drukowania poprzez printers:
uses printers;
procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
var
X1, X2: Integer;
Y1, Y2: Integer;
TmpI: Integer;
F: Integer;
TR: TRect;
begin
Printer.Title := sTitle;
Printer.BeginDoc;
Printer.Canvas.Pen.Color := 0;
Printer.Canvas.Font.Name := 'Times New Roman';
Printer.Canvas.Font.Size := 14;
Printer.Canvas.Font.Style := [fsBold, fsUnderline];
//Printer.Canvas.TextOut(0, 100, Printer.Title);
for F := 1 to sGrid.ColCount - 1 do
begin
X1 := 0;
for TmpI := 1 to (F - 1) do
X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
Y1 := 300;
X2 := 0;
for TmpI := 1 to F do
X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
Y2 := 450;
TR := Rect(X1, Y1, X2 - 30, Y2);
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.Font.Size := 12;
Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
Printer.Canvas.Font.Style := [];
for TmpI := 1 to sGrid.RowCount - 1 do
begin
Y1 := 150 * TmpI + 300;
Y2 := 150 * (TmpI + 1) + 300;
TR := Rect(X1, Y1, X2 - 30, Y2);
Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
end;
end;
Printer.EndDoc;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
PrintGrid(StringGrid1, 'Print Stringgrid');
end;
Przyznaję się, że w delphi to ja nie jestem erzoł:) Za pomoc bardzo będe dźwięczny:) pozdrufki