Excel - Wrap within Cell

HenryW

New Member
I have a program that sends more than 100 characters into a 40 character Excel field.

In Excel you can format the cell to be word Wrap and the 100 characters will wrap into 3 lines. In a Progress routine I can do the same.

However when you are using Excel directly if you use <alt> enter it will dictate where the line break is.

This is line one <alt> enter
This is Line two <alt> enter
This is Line three

I can't seem to figure out how I can send that sequence in a program. You can send CHR(10) etc but how do you send what you can type to the field?

Is this impossible or can it be done?
 
I have used "~n" before with success in creating an in-cell line break. I don't think I had to set wrapping for the cell or anything. It worked on both Excel 03 and 07.
 
Hi, some quick code:

DEFINE VARIABLE chExcel AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chBook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chSheet AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chNSheet AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE cChar AS CHARACTER NO-UNDO INITIAL "This is Line 2".

CREATE "Excel.Application":U chExcel.
ASSIGN
chExcel:Visible = FALSE
chExcel:DisplayAlerts = FALSE.
chBook = chExcel:Workbooks:Add.
chSheet = chBook:Sheets(1).

chSheet:Range("A1:B1"):MergeCells = True.
chSheet:Rows("1:1"):RowHeight = 50.
chSheet:Range("A1"):FormulaR1C1 = "This is Line 1" + "~n" + cChar + CHR(10) + "This is Line 3".

chExcel:Visible = TRUE.

RELEASE OBJECT chSheet.
RELEASE OBJECT chBook.
RELEASE OBJECT chExcel.


Hope this helps ! Just a reminder that autoformat on row height will be formatted to only view the first entry, so you'd have to know how many entries are in the cell in order to manually adjust the row height (think this might only apply if you merge cells).

Edit: "~n" and CHR(10) seems to work just fine (tested on Excel 07)
 
Back
Top