473,416 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Problem exporting to MS Excel

I am exporting data from an HTML table to MS Excel using ASP. Everything works fine except that data that is in one HTML cells separated by the "<BR>" export to MS Excel in 2 separate data cells in Excel. How can I make it go into one cell?

Thanx in advance..
Aug 23 '07 #1
2 2556
jhardman
3,406 Expert 2GB
This is because Excel uses new line characters as cell and row delimiters. I recommend treating "<br>" as a special character and escaping it to the phrase of your choice ("[br]" works nicely and is unlikely to be used for anything else, also "&lt;br&gt;" might work without any trouble when you retrieve it) then change it back to "<br>" after you retrieve the data. Would this work for your application?

Jared
Aug 23 '07 #2
Try this :

This code provides for the export of data from SQL server to Excel via two asp pages.
You could go directly to the 02extoex.asp page without showing 01viewdata.asp which
is only there to show the user the data first.

================================================== =============

PAGE ONE CALLED 01viewdata.asp :
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <!-- #include file="../incfiles/adovbs.inc" -->
  3. <% 
  4. dim Conn,RS1
  5.  
  6. '==================CONNECTION CODE=======================
  7. Set Conn = Server.CreateObject("ADODB.Connection")
  8. Set RS1 = Server.CreateObject("ADODB.RecordSet")
  9.  
  10. strConn = "Provider=SQLOLEDB;Data Source=LAPTOP01;Initial Catalog=polpact;"&_
  11. "User Id=logger;Password=logger;"
  12. Conn.Open strConn 
  13. '==================CONNECTION CODE=======================
  14.  
  15. sql1 = "Select * from tblAccessLog WHERE LogID < 10000" 
  16.  
  17. RS1.Open sql1, Conn
  18.  
  19. If RS1.eof Then
  20. %>
  21.  
  22.  
  23.  
  24. <html>
  25. <body>
  26. <table border="0" width="100%" cellspacing="0" cellpadding="2">
  27.     <tr>
  28.         <td>&nbsp;<font face="Arial" color="#FF0000" size="2">No Records Match Your Search</font></td>
  29.     </tr>
  30. </table>
  31.  
  32. <%Else%>
  33. <form method="POST" action="02extoex.asp">
  34. <table border=0 width="100%" cellspacing="0" cellpadding="2">
  35. <tr>
  36. <td>
  37. <input type="submit" value="Export To Excel Spread Sheet" name="B1" style="font-size: 8pt">&nbsp;
  38. <input type="hidden" name="InpSQL" size="63" value="<%=sql1%>"></td>
  39. </tr>
  40. </table>
  41. </form>
  42.  
  43. <table border="1" width="100%" cellspacing="0" cellpadding="2" bordercolor="#000000">
  44.     <tr>
  45.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log ID</font></td>
  46.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Date</font></td>
  47.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Time</font></td>
  48.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log User</font></td>
  49.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log IP Rem</font></td>
  50.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log IP Loc</font></td>
  51.         <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Page</font></td>
  52.     </tr>
  53.     <%Do While Not RS1.eof%>
  54.     <tr>
  55.         <td><font face="Arial" size="2"><%=RS1("LogID")%></font></td>
  56.         <td><font face="Arial" size="2"><%=RS1("LogDate")%></font></td>
  57.         <td><font face="Arial" size="2"><%=RS1("LogTime")%></font></td>
  58.         <td><font face="Arial" size="2"><%=RS1("LogUser")%></font></td>
  59.         <td><font face="Arial" size="2"><%=RS1("LogIPRem")%></font></td>
  60.         <td><font face="Arial" size="2"><%=RS1("LogIPLoc")%></font></td>
  61.         <td><font face="Arial" size="2"><%=RS1("LogPage")%></font></td>
  62.     </tr>
  63.     <%
  64.     RS1.Movenext
  65.     Loop
  66.     End If
  67.     %>
  68. </table>
  69.  
  70.  
  71.  
  72. </td></tr>
  73. </table>
  74. </body>
  75. </html>
  76.  
  77. <%
  78. RS1.Close
  79. Conn.Close
  80.  
  81. Set Conn = Nothing
  82. Set RS1 = Nothing
  83. %>
  84.  
================================================== =============

PAGE TWO CALLED 02extoex.asp :
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <!-- #include file="../incfiles/adovbs.inc" -->
  3. <% 
  4. dim Conn,RS1
  5.  
  6. sql1 = Request("InpSQL")
  7.  
  8. '==================CONNECTION CODE=======================
  9. Set Conn = Server.CreateObject("ADODB.Connection")
  10. Set RS1 = Server.CreateObject("ADODB.RecordSet")
  11.  
  12. strConn = "Provider=SQLOLEDB;Data Source=LAPTOP01;Initial Catalog=polpact;"&_
  13. "User Id=logger;Password=logger;"
  14. Conn.Open strConn 
  15. '==================CONNECTION CODE=======================
  16.  
  17. 'sql1 = "Select * from tblAccessLog WHERE LogID < 10000" 
  18.  
  19. RS1.Open sql1, Conn
  20.  
  21.  
  22. Response.ContentType = "application/vnd.ms-excel"
  23. Response.AddHeader "Content-Disposition", "attachment; filename=export.xls" 
  24. %>
  25.  
  26. <table border="1" width="100%">
  27.     <tr>
  28.         <td bgcolor="#000080"><font color="#FFFFFF">Log ID</font></td>
  29.         <td bgcolor="#000080"><font color="#FFFFFF">Log Date</font></td>
  30.         <td bgcolor="#000080"><font color="#FFFFFF">Log Time</font></td>
  31.         <td bgcolor="#000080"><font color="#FFFFFF">Log User</font></td>
  32.         <td bgcolor="#000080"><font color="#FFFFFF">Log IP Rem</font></td>
  33.         <td bgcolor="#000080"><font color="#FFFFFF">Log IP Loc</font></td>
  34.         <td bgcolor="#000080"><font color="#FFFFFF">Log Page</font></td>
  35.     </tr>
  36.     <%Do While Not RS1.eof%>
  37.     <tr>
  38.         <td><%=RS1("LogID")%></td>
  39.         <td><%=RS1("LogDate")%></td>
  40.         <td><%=RS1("LogTime")%></td>
  41.         <td><%=RS1("LogUser")%></td>
  42.         <td><%=RS1("LogIPRem")%></td>
  43.         <td><%=RS1("LogIPLoc")%></td>
  44.         <td><%=RS1("LogPage")%></td>
  45.     </tr>
  46.     <%
  47.     RS1.Movenext
  48.     Loop
  49.     %>
  50. </table>
  51.  
  52. <%
  53. RS1.Close
  54. Conn.Close
  55.  
  56. Set Conn = Nothing
  57. Set RS1 = Nothing
  58. %>
  59.  
================================================== =======================
Sep 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
4
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear"...
2
by: G | last post by:
When I export data from access to excel by with "export" or "Analyze with" I seem to loose parts of some fields (long text strings). Is there a way to export it all to excel? Thanks G
2
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
1
by: NancyA | last post by:
I am using the following code to write data from a datagrid to an Excel file: Dim tw As New System.IO.StringWriter Dim hw As New System.Web.UI.HtmlTextWriter(tw) dg.RenderControl(hw)...
2
by: Mustufa Baig | last post by:
Hi everybody, I have an ASP.NET website where clients can view their monthly billings by selecting different options. One of the option is the way they want to see the report i.e. whether they...
1
by: Mustufa Baig | last post by:
I have an ASP.NET website where I am showing off crystal reports to users by exporting them to pdf format. Following is the code: ---------------- 1 Private Sub ExportReport() 2 Dim oStream...
2
by: bienwell | last post by:
Hi, I have a question about exporting data from datagrid control into Excel file in ASP.NET. On my Web page, I have a linkbutton "Export data". This link will call a Sub Function to perform...
2
by: Snozz | last post by:
The short of it: If you needed to import a CSV file of a certain structure on a regular basis(say 32 csv files, each to one a table in 32 databases), what would be your first instinct on how to...
4
by: Tom | last post by:
I have a gridview on all of my web pages in my web app and they all export to excel. I have one page where the gridview is binding to a datatable that i created and only the first column is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.