S
superrgf
Unregistered / Unconfirmed
GUEST, unregistred user!
function ModSaveXlsFile(FilePath: string): Integer;
var
ExcelApp: Variant;
i,ColCount: integer;
TmpXlsFile: String;
begin
result := S_False;
{修改Excel文件格式}
try
ExcelApp := CreateOleObject( 'Excel.Application' );
except
exit;
end;
try
ExcelApp.Visible := false;
ExcelApp.WorkBooks.Open( FilePath );
ExcelApp.WorkSheets[1].Activate;
{设置列宽}
for i := 1 to 5 do
Range.Columns.ColumnWidth := 18;
{设置显示格式}
Excelapp.ActiveSheet.Columns[3].select;
Excelapp.Columns[3].NumberFormatLocal := '0.00';//金额
Excelapp.ActiveSheet.Columns[5].select;
Excelapp.Columns[5].NumberFormatLocal := '0';//银行账号
{
这儿能否没有提示直接保存,不需要另存为临时文件,哪位有高见?
}
{保存为临时文件}
//TmpXlsFile := ExtractFilePath(FilePath)+'tmp.xls';
//ExcelApp.ActiveSheet.Saveas(TmpXlsFile);
//if not VarIsEmpty(ExcelApp) then
//ExcelApp.ActiveWorkBook.Saved := True; //不出现保存对话框但保存不了修改
finally
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp := unassigned;
end;
{把临时文件更名为所需文件
if FileExists(FilePath) then
if DeleteFile(FilePath) then
RenameFile(TmpXlsFile,FilePath);}
result := S_OK;
end;
var
ExcelApp: Variant;
i,ColCount: integer;
TmpXlsFile: String;
begin
result := S_False;
{修改Excel文件格式}
try
ExcelApp := CreateOleObject( 'Excel.Application' );
except
exit;
end;
try
ExcelApp.Visible := false;
ExcelApp.WorkBooks.Open( FilePath );
ExcelApp.WorkSheets[1].Activate;
{设置列宽}
for i := 1 to 5 do
Range.Columns.ColumnWidth := 18;
{设置显示格式}
Excelapp.ActiveSheet.Columns[3].select;
Excelapp.Columns[3].NumberFormatLocal := '0.00';//金额
Excelapp.ActiveSheet.Columns[5].select;
Excelapp.Columns[5].NumberFormatLocal := '0';//银行账号
{
这儿能否没有提示直接保存,不需要另存为临时文件,哪位有高见?
}
{保存为临时文件}
//TmpXlsFile := ExtractFilePath(FilePath)+'tmp.xls';
//ExcelApp.ActiveSheet.Saveas(TmpXlsFile);
//if not VarIsEmpty(ExcelApp) then
//ExcelApp.ActiveWorkBook.Saved := True; //不出现保存对话框但保存不了修改
finally
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp := unassigned;
end;
{把临时文件更名为所需文件
if FileExists(FilePath) then
if DeleteFile(FilePath) then
RenameFile(TmpXlsFile,FilePath);}
result := S_OK;
end;