hallo,
hier noch ein Beispiel, als Ergänzung zu #6
Delphi-Quellcode:
var
excel_obj: OleVariant;
xml_path,
xlsx_name,
sheet_name: string;
cell_start,
letzte_zeile,
row_start,
col_indx,
sheet_indx,
i: integer;
my_value: OLEVariant;
function get_sheet_values: Boolean;
var
i: integer;
begin
try
excel_obj.workbooks.open(xml_path + xlsx_name);
excel_obj.activeworkbook.worksheets[sheet_name].activate;
letzte_zeile := excel_obj.Worksheets[sheet_indx].Cells[excel_obj.Worksheets[sheet_indx].rows.count, col_indx].end[xlUp].row;
for i := row_start to letzte_zeile do
begin
if excel_obj.Worksheets[1].cells[i, col_indx].value <> '..' then
memo1.lines.add(excel_obj.Worksheets[sheet_indx].cells[i, col_indx].value)
end;
result := true;
except
result := false;
end;
end;
function write_sheet_values:Boolean;
var
i: integer;
begin
try
excel_obj.workbooks.add();
for i := 0 to memo1.lines.count - 1 do
excel_obj.activeworkbook.worksheets[1].cells[1 + i, 1].value := memo1.lines[i];
excel_obj.activeworkbook.saveas(xml_path + 'neu.xlsx');
result:=true;
finally
result:=false;
end;
end;
begin
memo1.clear;
excel_obj := unassigned;
xml_path := extractfiledir(application.ExeName) + '\';
xlsx_name := 'Mappe1.xlsx';
sheet_name := 'Tabelle1';
sheet_indx := 1;
row_start:=1;
col_indx := 4;
excel_obj := createoleobject('Excel.application');
try
if get_sheet_values=True then write_sheet_values;
finally
excel_obj.quit;
excel_obj := unassigned;
end;
end;
Dient jetzt nur als Demo, ist natürlich verbesserungs bedürftig
Gruß