Solved

Line feed within cell/ formatting within cell in Excel

Posted on 2004-04-21
12
681 Views
Last Modified: 2007-12-19
Experts,

I have a search engine and it gives results in HTML.  The results has to be dumped in EXcel sheet according to a certain format.

I have a small trial program that can be executed.   This code prints data on seperate cells.  How can I give line feed inside one single cell ?  Please help me with the code and modifiy it so that I can get Line2 below line1 in a single cell.  If this is not the right place to ask this question, please direct me to the right location.

Here is the code:

<%
Response.Expires = -1000

Const cDocFolderRoot = "virtual"
Const cDocFolderPath = "\data\doctemp\"

Dim oXLS, mXLSFile, mPathInternal, mPathVirtual

mXLSFile = getFileName(Session("UserID"))

     Const cDocFolder = "\data\doctemp"
     Const cXLSext = ".xls"

     Dim thePath, theFile

mPathInternal = Server.MapPath("/" & cDocFolderRoot) & cDocFolderPath
mPathVirtual = cDocFolderRoot & Replace(cDocFolderPath, "\", "/")


' Use Office Web Components
Set oXLS = Server.CreateObject("OWC.Spreadsheet")

'!!! problem: Chr(10) or Chr(13) causing data to be written to the next cell down
oXLS.Cells(1, 1).Value = "Line1" & Chr(10) & "Line2"


'!!! problem: file not written if already exists
oXLS.ActiveSheet.Export mPathInternal & mXLSFile, 0

'!!! doesn't work - client not able to access file from internal map
' Response.Redirect mPathInternal & mXLSFile

Set oXLS = Nothing


Function getFileName(ByVal pDowID)
'
' return an Excel file name
'
     getFileName = "ProdMix_" & getDateStamp(Date) & "_" & pDowID & cXLSext

End Function

Function getDateStamp(ByVal pDate)
'
' return date string in the form yyyy-mmm-dd
'
     Dim yy, mm, dd

     yy = Year(pDate)
     mm = MonthName(Month(pDate), True)
     dd = Day(pDate)
     If dd < 10 Then dd = "0" & dd


     getDateStamp = yy & "-" & mm & "-" & dd

End Function
%>

<html>
<body>

<h2>Excel Test</h2>

<p><a href="<%=mPathVirtual & mXLSFile %>">click here for spreadsheet</a></p>

<p>
<br>
<b>Debug:</b>
<br>
<br>
mPathInternal = <%=mPathInternal %><br>
mPathVirtual = <%=mPathVirtual %><br>
mXLSFile = <%=mXLSFile %><br>
</p>

<p>Refreshed: <%=Date() & " " & Time() %></p>

</body>
</html>
0
Comment
Question by:suran78
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 12

Expert Comment

by:AshleyBryant
ID: 10881030
You could build your HTML display to look exactly like the format is supposed to be in the excel file and just use Response.ContentType to tell the browser it is receiving an excel file instead of HTML.

<%
If Request.QueryString("display") = "excel" then
      Response.Expires = 0
      Response.Buffer = True
      Response.Clear
      Response.ContentType = "application/vnd.ms-excel"
End If
%>
<html>
<head>
      <title>Your page title</title>
</head>
<body>

<% If Not Request.QueryString("display") = "excel" then %>
<a href="pagename.asp?display=excel">Export to Excel</a>
<% End If %>

'build your table of search results here

</body>
</html>
0
 
LVL 12

Expert Comment

by:AshleyBryant
ID: 10881053
I should've been more clear there regarding the line feed issue.  I personally don't know of a way to tell excel to use a line feed via character code or using a VB Carriage Return (vbCr).  I do know that if you make an HTML table and have line breaks within your td tags, they will be treated as carriage returns in the exported excel file.
0
 

Author Comment

by:suran78
ID: 10881066
I have done this already.  The problem is I have to format lines in single cell.

So, it should look like this in single cell:
------------------
Line1 <br>
Line2
------------------

With Html fomating I am getting
first cell:
line1
--------------------
next cell
line2

suran
0
 
LVL 12

Expert Comment

by:AshleyBryant
ID: 10881219
Alas, you are correct.  My memory failed me.  If you put a border on your table, you can see that the cell borders will be in the right place, but the items still show up in different cells.
0
 
LVL 10

Expert Comment

by:Shailesh15
ID: 10881352
In excel VBA we can enter line feed as
Range("A1").Select
ActiveCell.FormulaR1C1 = "this is a test" & Chr(10) & "new line"

You need to activate the cell before inserting the line feed char (10).
In the same way ... you can try...
oXLS.Range("A1").Select
ActiveCell.FormulaR1C1 = "Line1" & Chr(10) & "Line2"

This is just a theory...good luck!


0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:suran78
ID: 10882014
Shailesh,

Thanks fo rreplying. I tried your code, the FormulaR1C1 is giving error.
0
 
LVL 10

Expert Comment

by:Shailesh15
ID: 10882252
did you try value property?..
ActiveCell.Value = "this is a test" & Chr(10) & "new line"

I was expecting error while range selection!
0
 

Author Comment

by:suran78
ID: 10882434
I am not getting any error by changing formulaR1C1 to value.  But teh spreadsheet is not opening and I am not getting any result.

suran
0
 

Author Comment

by:suran78
ID: 10882490
I tried
ActiveCell.Value = "this is a test" & Chr(10) & "new line"

The "new line" is still coming on next cell but not inside the single cell with "this is a test"

0
 

Author Comment

by:suran78
ID: 10882928
I have got the answer, please check this out, if you are eager to know teh solution:

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20959144.html

Thanks for replying and trying.
suran
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10962152
Closed, 250 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now