About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 35 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

When educated people disagree with you, it has nothing to do with political bias. They disagree with you because you're wrong.

Greg Saunders



Navigation





<April 2025>
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 4/29/2025

Totals
Posts - 2660
Comments - 2678
Hits - 2,739,932

Averages
Entries/day - 0.33
Comments/entry - 1.01
Hits/day - 343

Updated every 30 minutes. Last: 9:48 AM Pacific


  10:29 PM

I ran across this 2x in about 15 minutes, and it seemed like fun to try. You can "convert" your data to a downloadable spreadsheet in ASP.NET by 1) outputting it as an HTML table and 2) setting the page's ContentType to "application/vnd.ms-excel". (References/credit here and here.)

If you have Excel installed, try it by clicking here, where you get the 10 most recent blog entries (abbreviated) in a spreadsheet.

The code:
<%@ Page Language="VB" Debug="true" EnableViewState="False" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">

Sub Page_Load()
Dim ds As Dataset = GetBlog()
Dim dr As Datarow
Dim tableString As New StringBuilder
tableString.Append("<table border=1>")
tableString.Append("<thead><th>Title</th><th>EntryDate</th>" & _
"<th>Text</th></thead>")
For Each dr in ds.Tables(0).Rows
tableString.Append("<tr><td>" & dr("title") & _
"</td><td>" & dr("EntryDateTime") & "</td><td>" & _
Server.HtmlEncode(dr("ShortDescription")) & "</td></tr>")
Next
tableString.Append("</table>")
Literal1.Text = tableString.ToString()
Response.ContentType = "application/vnd.ms-excel"
End Sub

Function GetBlog() As System.Data.DataSet
Dim connectionString As String = _
ConfigurationSettings.AppSettings("connectionString")
Dim dbConnection As New SqlConnection(connectionString)
Dim queryString As String = "SELECT top 10 Title, EntryDateTime, " & _
" Substring(Description, 0, 25) As ShortDescription FROM [blog] " & _
" ORDER BY EntryDateTime DESC"
Dim dbCommand As New SqlCommand(queryString, dbConnection)
Dim dataAdapter As New SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Literal id="Literal1" runat="server"></asp:Literal>
</form>
</body>
</html>

[categories]  

[10] |

 
Excel in ASP.NET" trackback:ping="https://www.mikepope.com/blog/BlogTrackback.aspx?id=344" /> -->