Reputation: 53
I just installed Delphi XE3. The previous version was XE. My program generates Excel files (I am using Office 2013). I imported Excel Type Library. When I using Delphi XE then this code is working. When I using Delphi XE3 then I got an error message, something like this: 'HorizontalAlignment property can not be set' What is changed in XE3?
Here is the code:
VAR Myworkbook, range, excelapp : olevariant;
Begin
ExcelApp:=CreateOleObject('Excel.Application');
ExcelApp.Visible:=true;
MyWorkbook:=ExcelApp.Workbooks.Add;
MyWorkbook.Activate;
MyWorkbook.Activesheet.PageSetup.Orientation := xlPortrait;
MyWorkbook.Activesheet.PageSetup.PaperSize := xlPaperA4;
MyWorkbook.Activesheet.PageSetup.LeftMargin := CMtoPT(1);
MyWorkbook.Activesheet.PageSetup.RightMargin := CMtoPT(1);
MyWorkbook.Activesheet.PageSetup.TopMargin := cmtopt(1.5);
MyWorkbook.Activesheet.PageSetup.BottomMargin := cmtopt(1.5);
Range:=ExcelApp.Range['A1','A1'];
Range.HorizontalAlignment := xlLeft;
Range.VerticalAlignment := xlCenter;
END
Upvotes: 2
Views: 1681
Reputation: 53
I have the solution:
Range.VerticalAlignment := xlCenter
should be:
Range.VerticalAlignment := integer(xlCenter)
I have to convert the constant explicitly to integer. Here is where I found it: http://forums.embarcadero.com/thread.jspa?threadID=106493
Upvotes: 1
Reputation: 11213
I think because you are using late binding eg Declaring ExcelApp
as an olevariant
VAR Myworkbook, range, excelapp : olevariant;
Begin
ExcelApp:=CreateOleObject('Excel.Application');
Then anything you call on ExcelApp that is incorrect is handled by Excel rather than Delphi. This means that either HorizontalAlignment is a not settable property, or xlLeft is in some way incorrect.
It is unlikely this is anything to do with your version of Delphi.
Upvotes: 0