function compressDB(Afile:string):boolean;
//
var
DaoVar: OLEVariant;
begin
try
DaoVar := CreateOleObject('dao.DBEngine.36');
if FileExists('db.tmp') then deletefile('db.tmp');
// DaoVar.CompactDatabase(afile,'db.tmp'); //压缩无密码的数据库
//压缩有密码的数据库。注意:密码不能为空
DaoVar.CompactDatabase(afile,'db.tmp',';pwd='+SDefDataBasePwd+'',0,';pwd='+SDefDataBasePwd+'');
if deletefile(afile) then RenameFile('db.tmp',Afile);
result:=true;
except
result:=False;
end;
end;
{导出 Excel 表格}
procedure GenXlsFile(sPRG:TProgressBar;SDBGrid:TDBGrid;sDataSet:TADOQuery;Fn:String;Vis:Boolean);
//uses ComObj;
var
ExcelApp: Variant;
i,j:integer;
begin
try
ExcelApp := CreateOleObject('Excel.Application');
except
application.MessageBox('系统中的MS Excel软件没有安装或安装不正确!','错误',MB_ICONERROR+MB_OK);
exit;
end;
ExcelApp.visible:=vis;
try
excelapp.caption:='应用程序调用 Microsoft Excel';
ExcelApp.WorkBooks.Add;
//写入标题行
for i:=1 to sDBGrid.FieldCount do
begin
ExcelApp.Cells[1,i].Value:=sDBGrid.Columns[i-1].Title.Caption ;
end;
sprg.Max:=sDataSet.RecordCount; //插入进度条
sDataSet.First;
i:=2;
while not sDataSet.Eof do
begin
for j:=0 to sDataSet.Fields.Count-1 do
begin
ExcelApp.Cells[i,j+1].Value :=sDataSet.Fields[j].AsString;
end;
sDataSet.Next;
i:=i+1;
sprg.StepBy(1); //进度条步长
end;
sDataSet.First;
sPrg.Position :=0; //
if application.MessageBox('数据导出完成.确认保存吗?','信息提示',MB_ICONQUESTION+MB_YESNO+MB_DEFBUTTON1+MB_SYSTEMMODAL)=IDYES then
begin
if not ExcelApp.ActiveWorkBook.Saved then
ExcelApp.ActiveWorkBook.SaveAs(fn);
end
else begin
ExcelApp.ActiveWorkBook.Saved := True; //不保存
end;
finally
excelapp.quit; //退出EXCEL软件
end;
end;
忘性大,关于ACCESS的一点点。
最新推荐文章于 2020-04-02 18:26:27 发布