18-05-2020, 02:45 PM
السلام عليكم
أحاول أن أًحول التحويل من ملف الاكسيل إلى ملف نصي تم التحويل من الاكسيل إلى stringGrid والان عندي مشكل مع الـ format()
هل من إقتراحات
أحاول أن أًحول التحويل من ملف الاكسيل إلى ملف نصي تم التحويل من الاكسيل إلى stringGrid والان عندي مشكل مع الـ format()
هل من إقتراحات
كود :
type
TForm3 = class(TForm)
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
ExcelFile,sheet : Variant;
procedure OpenExcelFile;
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
Var
MaxRow, MaxCol,i,j:Integer;
begin
OpenExcelFile;
MaxRow := Sheet.Usedrange.Rows.count ;
MaxCol := sheet.Usedrange.Columns.count;
stringgrid1.RowCount:=maxRow+1;
StringGrid1.ColCount:=maxCol+1;
for I := 1 to MaxCol do
begin
for j := 1 to MaxRow do
begin
stringgrid1.Cells[i,j]:=excelfile.cells[j,i].value;
end;
end;
ExcelFile.workbooks.close;
ExcelFile.quit;
ExcelFile:=Unassigned;
end;
procedure TForm3.Button2Click(Sender: TObject);
var f: TextFile;
i: Integer;
begin
AssignFile(f,'d:\1.txt');
Rewrite(f);
with StringGrid1 do
begin
for i := 1 to RowCount - 1 do
begin
Write(F, '*'+Cells[1, i]);
Write(F, format('%s',cells[2, i]));
Write(F, Cells[3, i]);
Write(F, Cells[4, i]);
Write(F, Cells[5, i]);
writeln(f);
end;
end;
CloseFile(F);
end;
procedure TForm3.OpenExcelFile;
begin
ExcelFile := CreateOleObject('Excel.Application');
ExcelFile.visible:=0;
ExcelFile.Workbooks.Open('C:\Users\HAT\Desktop\book1.xls');
sheet := ExcelFile.WorkSheets[1];
end;
end.
