?
Solved

How to use Word Wrap for Excel through Delphi

Posted on 2006-10-19
1
Medium Priority
?
2,118 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 1000 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

Industry Leaders: 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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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