473,769 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems with Rows in Excel after downloading sql database info through webpage

1 New Member
Hi,

I am trying to download sql database through asp on my webpage and I keep getting weird outcomes in Excel. I have had to put in <char10> and <char13> into my sql data to have it display properly on the webpage and I know this is messing with the csv file download.

What it is doing in excel is breaking the "breaks" into multiple rows per recordset.

Here is my download code, is there anyway to fix this without removing them from my database?
Expand|Select|Wrap|Line Numbers
  1. response.expires = 0
  2.  
  3. dim i,x,y,rst,F,Head,SQLstring,tempstring, dbfield, hdr
  4.  
  5. public function replacebrComma(dbfield)
  6.     if len(dbfield)>0 then
  7.         replacebrComma=replace(replace(replace(replace(dbfield,"<br>",""),Chr(10),""),Chr(13),""),",","")
  8.     else
  9.         replacebrComma=""
  10.     end if
  11. end function
  12.  
  13. SQLstring =  "Select * from FourBlocker"
  14. set rst = my4Blocker.execute(SQLstring)
  15.  
  16.  
  17. response.contenttype = "application/vnd.ms-excel"
  18. response.write("<TABLE border='1'")
  19.  
  20. i=0
  21. for each f in rst.fields
  22.     i=i+1
  23.     hdr = hdr & "<TD>" & f.name & "</TD>"
  24.     'g = g & ", " & f.name
  25. next
  26. response.write("<TR><TD colspan='" & i & "'>Fourblocker Data Download</TD></TR>")
  27. response.write("<TR>" & hdr & "</TR>")
  28. alldata = rst.getrows
  29. for x=0 to ubound(alldata,2)
  30.     response.write("<TR>")
  31.     for y=0 to ubound(alldata,1)
  32.         if alldata(y,x) <> "" then
  33.             response.write("<TD>" & replace(alldata(y,x),"<BR>"," " & chr(10)) & "</TD>")    
  34.         else
  35.             response.write("<TD>" & alldata(y,x) & "</TD>")    
  36.         end if
  37.     next
  38.     response.write("</TR>")
  39. next
  40. response.write("</TABLE>")
Feb 21 '08 #1
1 1553
Merlin1857
14 New Member
Try this :

Expand|Select|Wrap|Line Numbers
  1.  
  2. This code provides for the export of data from SQL server to Excel via two asp pages.
  3. You coould go directly to the 02extoex.asp page without showing 01viewdata.asp which
  4. is only there to show the user the data first.
  5.  
  6. =============================================================== 
  7.  
  8. PAGE ONE CALLED 01viewdata.asp :
  9.  
  10. <%@ Language=VBScript %>
  11. <!-- #include file="../incfiles/adovbs.inc" -->
  12. <% 
  13. dim Conn,RS1
  14.  
  15. '==================CONNECTION CODE=======================
  16. Set Conn = Server.CreateObject("ADODB.Connection")
  17. Set RS1 = Server.CreateObject("ADODB.RecordSet")
  18.  
  19. strConn = "Provider=SQLOLEDB;Data Source=LAPTOP01;Initial Catalog=polpact;"&_
  20. "User Id=logger;Password=logger;"
  21. Conn.Open strConn 
  22. '==================CONNECTION CODE=======================
  23.  
  24. sql1 = "Select * from tblAccessLog WHERE LogID < 10000" 
  25.  
  26. RS1.Open sql1, Conn
  27.  
  28. If RS1.eof Then
  29. %>
  30.  
  31.  
  32.  
  33. <html>
  34. <body>
  35. <table border="0" width="100%" cellspacing="0" cellpadding="2">
  36.  <tr>
  37.   <td>&nbsp;<font face="Arial" color="#FF0000" size="2">No Records Match Your Search</font></td>
  38.  </tr>
  39. </table>
  40.  
  41. <%Else%>
  42. <form method="POST" action="02extoex.asp">
  43. <table border=0 width="100%" cellspacing="0" cellpadding="2">
  44. <tr>
  45. <td>
  46. <input type="submit" value="Export To Excel Spread Sheet" name="B1" style="font-size: 8pt">&nbsp;
  47. <input type="hidden" name="InpSQL" size="63" value="<%=sql1%>"></td>
  48. </tr>
  49. </table>
  50. </form>
  51.  
  52. <table border="1" width="100%" cellspacing="0" cellpadding="2" bordercolor="#000000">
  53.  <tr>
  54.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log ID</font></td>
  55.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Date</font></td>
  56.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Time</font></td>
  57.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log User</font></td>
  58.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log IP Rem</font></td>
  59.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log IP Loc</font></td>
  60.   <td bgcolor="#000080"><font face="Arial" size="2" color="#FFFFFF">Log Page</font></td>
  61.  </tr>
  62.  <%Do While Not RS1.eof%>
  63.  <tr>
  64.   <td><font face="Arial" size="2"><%=RS1("LogID")%></font></td>
  65.   <td><font face="Arial" size="2"><%=RS1("LogDate")%></font></td>
  66.   <td><font face="Arial" size="2"><%=RS1("LogTime")%></font></td>
  67.   <td><font face="Arial" size="2"><%=RS1("LogUser")%></font></td>
  68.   <td><font face="Arial" size="2"><%=RS1("LogIPRem")%></font></td>
  69.   <td><font face="Arial" size="2"><%=RS1("LogIPLoc")%></font></td>
  70.   <td><font face="Arial" size="2"><%=RS1("LogPage")%></font></td>
  71.  </tr>
  72.  <%
  73.  RS1.Movenext
  74.  Loop
  75.  End If
  76.  %>
  77. </table>
  78.  
  79.  
  80.  
  81. </td></tr>
  82. </table>
  83. </body>
  84. </html>
  85.  
  86. <%
  87. RS1.Close
  88. Conn.Close
  89.  
  90. Set Conn = Nothing
  91. Set RS1 = Nothing
  92. %>
  93.  
  94. ===============================================================
  95.  
  96. PAGE TWO CALLED 02extoex.asp :
  97.  
  98. <%@ Language=VBScript %>
  99. <!-- #include file="../incfiles/adovbs.inc" -->
  100. <% 
  101. dim Conn,RS1
  102.  
  103. sql1 = Request("InpSQL")
  104.  
  105. '==================CONNECTION CODE=======================
  106. Set Conn = Server.CreateObject("ADODB.Connection")
  107. Set RS1 = Server.CreateObject("ADODB.RecordSet")
  108.  
  109. strConn = "Provider=SQLOLEDB;Data Source=LAPTOP01;Initial Catalog=polpact;"&_
  110. "User Id=logger;Password=logger;"
  111. Conn.Open strConn 
  112. '==================CONNECTION CODE=======================
  113.  
  114. 'sql1 = "Select * from tblAccessLog WHERE LogID < 10000" 
  115.  
  116. RS1.Open sql1, Conn
  117.  
  118.  
  119. Response.ContentType = "application/vnd.ms-excel"
  120. Response.AddHeader "Content-Disposition", "attachment; filename=export.xls" 
  121. %>
  122.  
  123. <table border="1" width="100%">
  124.  <tr>
  125.   <td bgcolor="#000080"><font color="#FFFFFF">Log ID</font></td>
  126.   <td bgcolor="#000080"><font color="#FFFFFF">Log Date</font></td>
  127.   <td bgcolor="#000080"><font color="#FFFFFF">Log Time</font></td>
  128.   <td bgcolor="#000080"><font color="#FFFFFF">Log User</font></td>
  129.   <td bgcolor="#000080"><font color="#FFFFFF">Log IP Rem</font></td>
  130.   <td bgcolor="#000080"><font color="#FFFFFF">Log IP Loc</font></td>
  131.   <td bgcolor="#000080"><font color="#FFFFFF">Log Page</font></td>
  132.  </tr>
  133.  <%Do While Not RS1.eof%>
  134.  <tr>
  135.   <td><%=RS1("LogID")%></td>
  136.   <td><%=RS1("LogDate")%></td>
  137.   <td><%=RS1("LogTime")%></td>
  138.   <td><%=RS1("LogUser")%></td>
  139.   <td><%=RS1("LogIPRem")%></td>
  140.   <td><%=RS1("LogIPLoc")%></td>
  141.   <td><%=RS1("LogPage")%></td>
  142.  </tr>
  143.  <%
  144.  RS1.Movenext
  145.  Loop
  146.  %>
  147. </table>
  148.  
  149. <%
  150. RS1.Close
  151. Conn.Close
  152.  
  153. Set Conn = Nothing
  154. Set RS1 = Nothing
  155. %>
  156.  
  157. =========================================================================
  158.  
  159.  
Feb 28 '08 #2

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

Similar topics

4
6139
by: shank | last post by:
Visually, the page will look somewhat like a spreadsheet. It could have hundreds of records (rows) displayed. I want to enable the user to edit any one or any number of records and any fields, then click a save button to UPDATE the SQL table. I'd like to use stored procedures if possible. How is this done? Where do I start? thanks
13
7782
by: Dixie | last post by:
How do I, in VBA from an access form module, add 5 rows to the top of a spreadsheet called MySpreadsheet.xls. The worksheet is called MyWorksheet and there is already data in the first 5 rows. I simply need to insert 5 blank rows at the top and move the rest of the data down so it starts at row 6. dixie
1
1206
by: Frank Bishop | last post by:
I am having problems downloading an Excel file after I export it with another procedure. When I look at the file after export, it looks fine, but when I use the sub below, it rearranges all the data in the excel file to an unreadable glob. Help appreciated. Thanks, Frank <code> Sub DisplayDownloadDialog() Dim ExportPath As String
6
6768
by: Daniel | last post by:
Hi all, Can i open and edit the excel sheet on web page after downloading? After editing, i close the web page and the excel file auto upload to the server. Is it possible? I really struggling about the ability. If not, what advice can u provide? thank you in advance. ur help will be appreaciated.
0
1720
by: Jim Seymour | last post by:
Hi, Environment: PostgreSQL 7.4.2 Locally built with GCC 3.3.1 Solaris 8 (Sparc) I have a relatively simple database created with...
3
2060
by: Adam Sandler | last post by:
Hello all, I'm trying to use VWD 2005 Express Edition to connect to a database. For my initial prototyping though, I'm just using an Excel spreadsheet as the source and everything resides on the local host. All I want to do right now is get the info from the source and display it on a webpage. I've dropped a GridView and a SQLDataSource onto the page and here's the code:
2
3577
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
1
1319
by: =?Utf-8?B?Sm9obiBXYWxrZXI=?= | last post by:
Hi, I am using the code below to export a webpage to Excel. The webpage has three datagrids on it and they are all exported to Excel properly and everything looks very nice, but we would really only like two of the three datagrids to be exported. Is there a way to exclude certain sections of the webpage from being exported to Excel? "DG" in the code here is one of the datagrids on the page: ...
3
3005
by: scoots987 | last post by:
What do others do if you need to import excel files into SQL Server? My main problems are 1) zipcode formatting issues. If the column is a mix of zip and zip+4, I have problems retrieving all zipcodes. 2) If the last column contains NULL no information is imported. All this with using the Management console using Import data in SQL Server 2005. I am simply trying to import the data into NEW databases.
0
9579
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
9422
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,...
0
10038
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
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...
1
7404
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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();...
1
3952
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
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.