procedure
Timport
.
BitBtn1Click(Sender: TObject);
var
ExcelApp: Variant;
v_file:
String
;
begin
v_file:=(
'Импорт.xls'
);
SaveDialog1
.
FileName:=v_file;
If
SaveDialog1
.
Execute
then
begin
v_file:=SaveDialog1
.
FileName;
If
FileExists(v_file)
then
begin
If
Application
.
MessageBox(
PChar
(
'Файл "'
+v_file+
'" уже существует.'
+#
13
+
'Заменить существующий файл?'
),
'Сохранение'
,MB_YESNO+MB_ICONWARNING)<>
6
then
Exit;
end
;
SaveDBGridEhToExportFile(TDBGridEhExportAsXLS,
form2
.
DBGridEh1,v_file,
True
);
ExcelApp := CreateOleObject(
'Excel.Application'
);
ExcelApp
.
WorkBooks
.
Open(v_file);
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Cells[
1
,
1
] :=
'MARKA'
;
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Cells[
1
,
2
] :=
'DEVICE'
;
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Cells[
1
,
3
] :=
'ADDRESS'
;
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Cells[
1
,
4
] :=
'FIO'
;
ExcelApp
.
WorkBooks[
1
].WorkSheets[
1
].Cells[
1
,
5
] :=
'DATE'
;
ExcelApp
.
Columns
.
AutoFit;
ExcelApp
.
ActiveSheet
.
UsedRange
.
Columns
.
Borders
.
LineStyle:=
1
;
ExcelApp
.
ActiveSheet
.
UsedRange
.
Rows
.
Borders
.
LineStyle:=
1
;
ExcelApp
.
Workbooks
.
Close;
ExcelApp
.
Quit ;
ExcelApp := Unassigned;
If
Application
.
MessageBox(
PChar
(
'Файл "'
+v_file+
'" - сохранен'
+
#
13
+
'Открыть?'
),
'Вопрос'
,
MB_YESNO+MB_ICONQUESTION)=
6
then
begin
ExcelApp := CreateOleObject(
'Excel.Application'
);
ExcelApp
.
WorkBooks
.
Open(v_file);
ExcelApp
.
Visible :=
true
;
ExcelApp:=UnAssigned
end
;
DBGridEh1
.
SetFocus;
import
.
Button5
.
Enabled:=
true
;
end
;
end
;