Solved

How to use Word Wrap for Excel through Delphi

Posted on 2006-10-19
1
2,058 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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