Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Wrap in Export to Excel instead of line breaks

Author  Topic 

carriehoff
Starting Member

29 Posts

Posted - 2011-05-06 : 16:19:29
Hi all,

I form 4 different columns of a report with line breaks (I'm using <br/>). When I export the report from SQL to excel, each item is on its own line as I've attempted to show below. I would like the items to wrap, but cannot seem to find information on the character or characters that will do this.


1 1 0 3
1720 836 884 9
172 62 110 Q

If it helps, the record in my db looks like this:
col1: 1<br>1720<br>172
col2: 1<br>836<br>62
col3: 0<br>884<br>110
col4: 3<br>9<br>Q

What character or html code will make the field 'wrap' inside the excel cell? I'd like it to take up only 1 row instead of three.

Thank you,
Carrie Hoffmaster

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-05-06 : 16:28:19
just replace your line breaks with spaces
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-05-06 : 16:31:07
I'd suggest using CHAR(13)+CHAR(10) for Excel export. <br> and <p> are the only HTML tags for creating line breaks, and you don't want to use either of them for the purpose you described.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-05-06 : 18:10:45
Ahh, good call Rob
Go to Top of Page

carriehoff
Starting Member

29 Posts

Posted - 2011-05-09 : 09:09:36
As always, thank you. char(13) + char(10) almost give me what I want. Now I'm wondering if what I want is realistic.

When I open the excel file, the numbers appear like this in the cells:
1 1720 172
2 1 1569 233

I can manually drag the columns to force the cells to wrap. I can probably manually set the width in the export command to do this as well.

So it would seem that if I could preset the width and the height of the cells prior to the export, then the report would appear exactly as I want.
The problem is, that row 6 may wrap to 3 lines, but row7 can wrap to 4 lines. Some rows may wrap up to 8 lines.

Is there a way to show the entire contents of the cell, properly wrapped? How can I account for the varying height? I guess I'm looking for some kind of auto-fit option.
Then above example would look like this, I suppose:
(row 6)
1
1720
172
(row 7)
2
1
1569
233

I hope that makes sense. Even though I'm thinking that I'm going to have to go a different way with this.
Go to Top of Page
   

- Advertisement -