
21.05.2017, 04:45
|
Прохожий
|
|
Регистрация: 12.05.2010
Сообщения: 8
Репутация: 10
|
|
Сам код:
Код:
// основной код. Открываем один файл в Excel и потом перебираем другие, добавляя в него
LoadExcelFile(dir+'\main.xlsx');
fromr:=Excel.ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count+1;
for i := 0 to from.Count-1 do
begin
AddLog(IntToStr(i+1)+'/'+IntToStr(from.Count)+' Файл '+from.Strings[i]);
try
Mmex(i, fromr);
except
break;
end;
end;
// ну и функция. Открыли файл, добавили в основной, закрыли
procedure TForm1.MMEx(i: integer; var fromr: integer);
begin
LoadExcelFile2(from.Strings[i]);
kol:=Excel2.ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count;
Excel2.Range[Excel2.Cells.Item[2, 1], Excel2.Cells.Item[kol, 23]].Select;
Excel2.Selection.Copy;
Excel.ActiveSheet.Cells[fromr,1].Select;
Excel.ActiveSheet.Paste;
fromr:=fromr+kol-1;
Excel2.Application.Quit;
Excel2 := Unassigned;
end;
// само открытие, стандартное
function TForm1.LoadExcelFile2(file1: string): boolean;
begin
Excel2 := CreateOleObject('Excel.Application');
Excel2.Visible := false;
Excel2.DisplayAlerts := false;
Excel2.WorkBooks.Open(file1);
Result := true;
end;
function TForm1.LoadExcelFile(file1: string): boolean;
begin
Excel := CreateOleObject('Excel.Application');
Excel.Visible := false;
Excel.DisplayAlerts := false;
Excel.WorkBooks.Open(file1);
Result := true;
end;
|