Solved

How to use Word Wrap for Excel through Delphi

Posted on 2006-10-19
1
1,838 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
Comment Utility

   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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now