Solved

Line feed within cell/ formatting within cell in Excel

Posted on 2004-04-21
12
686 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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