Excel合并单元格后跨列居中一直无法实现。(50分)

  • 主题发起人 猎手1号
  • 开始时间

猎手1号

Unregistered / Unconfirmed
GUEST, unregistred user!
搜索了很多帖子,许多答案都无法实现:
uses ComObj;

var ExcelApp:Variant;

ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.WorkBooks.Add;
ExcelApp.Worksheets[2].activate;
......
ExcelApp.Range['B3:D3'].merge;
ExcelApp.Range['B3:D3'].VerticalAlignment:=xlCenter; //提示xlCenter未被定义
ExcelApp.Range['B3:D3'].VerticalAlignment:=-4108; //无效
ExcelApp.visible:=true;

谁能告诉我该如何解决?


 
uses
Excel2000, ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
ExcelApp:Variant;
begin
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.WorkBooks.Add;
ExcelApp.Worksheets[2].activate;

ExcelApp.Range['B3:D3'].merge;
ExcelApp.Range['B3'] := 'aaaa';
ExcelApp.Range['B3'].VerticalAlignment:=xlCenter; //提示xlCenter未被定义
ExcelApp.Range['B3'].HorizontalAlignment:=xlCenter; //提示xlCenter未被定义
ExcelApp.visible:=true;
end;
 
真是怪事了,加了Excel2000单元还是老样子,虽然不提示出错了:)=xlCenter那句)。
但打开表后还是没有居中。
 
你不是按我的代码贴上去的吧? 我的肯定没问题....
 
啊,我只设了垂直的,没设水平的,难怪了。多谢了!
 
注意方法,用 select 和 selection 就不会....
 
顶部