Solved

How to use Word Wrap for Excel through Delphi

Posted on 2006-10-19
1
1,996 Views
Last Modified: 2010-04-05
Lets say I have the following code (Which btw I got from the intelligent people here at EE):

procedure TForm1.Button1Click(Sender: TObject);
var
  XL, Sheet: Variant;
begin
  XL := CreateOleObject('Excel.Application');
  if XL.Workbooks.Count = 0 then begin
    XL.SheetsInNewWorkbook := 1;
    XL.Workbooks.Add;
  end else
    XL.ActiveWorkbook.WorkSheets.Add;
  XL.Visible := false;
  Sheet := XL.ActiveSheet;
  Sheet.Name := 'Excel Test';
  Sheet.Range['A1'] := 'Hello, world!';
  Sheet.Range['A2'] := 'This is a really long message that I need to write in the cell';

   Sheet.Columns.Range['A1','A1'].ColumnWidth:=30;
   Sheet.Rows.Range['A1','A1'].Font.Name:='Tahoma';
   Sheet.Rows.Range['A1','A1'].Font.Size:=8;
   Sheet.Rows.Range['A1','A1'].RowHeight:=30;

  XL.ActiveWorkbook.SaveAs(FileName:= 'c:\test.xls');
  XL.Quit;
end;

Now lets say on Cell A2 I need to format the cell to Word Wrap and center each line. How would I do that through the Delphi code?
0
Comment
Question by:powersolve
1 Comment
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 17768517

   Sheet.Rows.Range['A2','A2'].HorizontalAlignment:=-4108;
   Sheet.Rows.Range['A2','A2'].VerticalAlignment:=-4108;
   Sheet.Rows.Range['A2','A2'].WrapText:=True;


Regards,
Russell
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question