Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • putexcel

    Dear All,

    I need to write output to Excel. I am using -putexcel- for this purpose.
    In some of the cells, I need the content to be aligned on multiple lines (contain line breaks).
    (When working with Excel interactively this is done according to the steps shown here.)

    I have tried this with the following approach in Stata:
    Code:
        clear all
        putexcel set "C:\temp\out1.xlsx", replace
        putexcel A1 = ("AAA`=char(13)'BBB")
        putexcel save
    The result I am getting is a partial success: the edit line shows that there is a line break embedded into the content, but the content of the cell A1 is a run-together text of what I expected to be placed in two different lines.

    Click image for larger version

Name:	multiline.png
Views:	1
Size:	10.5 KB
ID:	1736376


    The correct result that I expect is shown in the next screenshot (B1 - manual edit).

    Click image for larger version

Name:	multiline2.png
Views:	1
Size:	11.0 KB
ID:	1736377



    I have experimented with:
    • including chars with codes (10), (13), (10 and 13) in various combinations,
    • adding option overwritefmt,
    but still no success.

    Can anyone suggest a way of getting the text properly aligned in multiple lines immediately from Stata code?

    Thank you very much,
    Sergiy Radyakin




  • #2
    Excel suppresses such linebreaks unless word wrap is on.

    Code:
    putexcel A1 = ("AAA`=char(10)'BBB"), txtwrap
    Note that either the newline or carriage return characters will move to a new line.

    Comment


    • #3
      Dear Leonardo,

      thank you very much for the prompt advice!! This solves the problem.

      I have also checked in Excel and see the 'Text Wrap' turns on automatically in the toolbar, when I insert any line breaks in the text content of a cell (which confirms your explanation).

      Best, Sergiy

      Comment

      Working...
      X