473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem exporting to MS Excel

1 New Member
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 2575
jhardman
3,406 Recognized Expert Specialist
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
Merlin1857
14 New Member
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
9248
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 only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
4
3949
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" TEXT field that contains data such as 2000/01, 2001/02, etc. If I export a Query with this kind of data to Excel, it gives me the text value of this field; however, when I export a Report bound to this TEXT field, Excel gives me the values 36526,...
2
7711
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
8013
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
2325
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) Response.ContentType = "application/vnd.ms-excel" Response.Charset = "" Response.AppendHeader("content-disposition", "attachment;filename=test.xls") Response.Write(txtWriter.ToString) Response.End()
2
6930
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 want to see it in PDF or EXCEL etc etc..... What I am trying to acheive is depending on their choice of format, I want to send the stream of that particulae selected format to the browser. I have tried couple od solutions but I couldn't able to get...
1
3169
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 As System.IO.MemoryStream = 3 myReport.ExportToStream( ExportFormatType.PortableDocFormat) 4 Response.Clear() 5 Response.Buffer() = True
2
2415
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 exporting ALL data from the datagrid control. Exporting data works fine when I show all data on the datagrid control. I'd like to shows only 30 records on the datagrid control instead of ALL data using page navigation, and perform exporting...
2
3184
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 set this up so as to do it reliably and minimize overhead? There are currently no constraints on the destination table. Assume the user or some configuration specifies the database name, server name, and filename+fullpath. The server is SQL...
4
2518
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 exporting to excel. How can I get the entire grid to export to excel?
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.