男
男生111
Unregistered / Unconfirmed
GUEST, unregistred user!
我在程序中用OLE向EXCEL写一些数据,需要设置列的宽度,用ColumnsWidth但是程序抱错,
Method 'ColumnsWidth' not supported by automation object 这是为什么,谢谢,程序如下
try
Application.ProcessMessages;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Caption := 'Microsoft Excel';
ExcelApp.WorkBooks.Add;
Application.ProcessMessages;
ExcelApp.WorkSheets[1].Activate;
except
showmessage('--没有安装Excel或excel出问题--');
exit;
end;
if SaveDialog1.Execute then
begin
filename:=SaveDialog1.FileName;
if pos('.xls',filename)=0 then
filename:=filename+'.xls';
end
else
exit;
////////format
ExcelApp.Columns[1].ColumnsWidth:=5;
/////////
ExcelApp.Cells[1, 3] := 'LLL';
ExcelApp.Cells[2, 1].Font.Size:=10;
ExcelApp.Cells[2, 1] := '填表单位:武清营业所';
ExcelApp.Cells[2, 5].Font.Size:=10;
ExcelApp.Cells[2, 5] := '填表时间:';
ExcelApp.Cells[3, 2] := '单位';
ExcelApp.Cells[3, 3] := '本月';
ExcelApp.Cells[3, 4] := '累积';
ExcelApp.Cells[3, 6] := '单位';
ExcelApp.Cells[3, 7] := '本月';
ExcelApp.Cells[3, 8] := '累积';
ExcelApp.Columns.AutoFit;
ExcelApp.ActiveWorkBook.SaveAs(filename);
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
showmessage('导出成功');
Method 'ColumnsWidth' not supported by automation object 这是为什么,谢谢,程序如下
try
Application.ProcessMessages;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Caption := 'Microsoft Excel';
ExcelApp.WorkBooks.Add;
Application.ProcessMessages;
ExcelApp.WorkSheets[1].Activate;
except
showmessage('--没有安装Excel或excel出问题--');
exit;
end;
if SaveDialog1.Execute then
begin
filename:=SaveDialog1.FileName;
if pos('.xls',filename)=0 then
filename:=filename+'.xls';
end
else
exit;
////////format
ExcelApp.Columns[1].ColumnsWidth:=5;
/////////
ExcelApp.Cells[1, 3] := 'LLL';
ExcelApp.Cells[2, 1].Font.Size:=10;
ExcelApp.Cells[2, 1] := '填表单位:武清营业所';
ExcelApp.Cells[2, 5].Font.Size:=10;
ExcelApp.Cells[2, 5] := '填表时间:';
ExcelApp.Cells[3, 2] := '单位';
ExcelApp.Cells[3, 3] := '本月';
ExcelApp.Cells[3, 4] := '累积';
ExcelApp.Cells[3, 6] := '单位';
ExcelApp.Cells[3, 7] := '本月';
ExcelApp.Cells[3, 8] := '累积';
ExcelApp.Columns.AutoFit;
ExcelApp.ActiveWorkBook.SaveAs(filename);
ExcelApp.WorkBooks.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
showmessage('导出成功');