Solved

How to use Word Wrap for Excel through Delphi

Posted on 2006-10-19
1
1,955 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 100
tidtcpserver connection lost handle 2 102
Not able to call Delphi XE10 dll function from Delphi 6.0 4 37
Wincontrol not (correctly) drawn 15 40
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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