I´m not familiar with JSON data parsing. So far, this is what I´ve come up to through web research:
data to parse:
https://api.twitch.tv/kraken/streams/
I´m trying to use the JSON.NET/VB.NET framework to do so:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
'(inside a function)
Dim json As JObject = JObject.Parse("https://api.twitch.tv/kraken/streams/")
strResult As String = json.SelectToken("streams").SelectToken("game")
It´s returning me an error message, and I´m sure I don´t have the structure right. How could I make this work? And afterwards, I´d like to loop through the results of the returning array.
Thanks,
This should get you going (just a conceptual example - console, not asp.net):
Dim json As JObject = _
JObject.Parse(New WebClient().DownloadString("https://api.twitch.tv/kraken/streams/"))
If json IsNot Nothing AndAlso json.HasValues Then
If json.SelectTokens("streams") IsNot Nothing _
AndAlso json.SelectTokens("streams").Children().Any() Then
Dim games() As JToken = json.SelectTokens("streams").Children().ToArray()
For Each child As JToken In games
Console.WriteLine("game title: {0} game id: {1} for mature audience? {2}", _
child.Item("game"), child.Item("_id"), child.Item("channel").Item("mature"))
Console.WriteLine()
Next
Console.ReadLine()
End If
End If
Hth....
This is the code simplified, with the help of EdSF, for the newbies in json (like myself):
Dim apiURL As String = "https://api.twitch.tv/kraken/streams?limit=10&offset=0"
Dim json As JObject = JObject.Parse(New WebClient().DownloadString(apiURL))
If json IsNot Nothing AndAlso json.HasValues Then
If json.SelectTokens("streams") IsNot Nothing AndAlso json.SelectTokens("streams").Children().Any() Then
Dim games() As JToken = json.SelectTokens("streams").Children().ToArray()
For Each child As JToken In games
'Console.WriteLine("game title: {0} game id: {1} for mature audience? {2}", child.Item("game"), child.Item("_id"), child.Item("channel").Item("mature"))
'Console.WriteLine()
lblMensagemSucesso.Text &= "_id=" & child.Item("_id").ToString() & "<br>"
lblMensagemSucesso.Text &= "game=" & child.Item("game").ToString() & "<br>"
lblMensagemSucesso.Text &= "viewers=" & child.Item("viewers").ToString() & "<br>"
lblMensagemSucesso.Text &= "preview=" & child.Item("preview").ToString() & "<br>"
lblMensagemSucesso.Text &= "preview.small=" & child.Item("preview").Item("small").ToString() & "<br>"
lblMensagemSucesso.Text &= "<img src='" & child.Item("preview").Item("small").ToString() & "'/><br>"
lblMensagemSucesso.Text &= "_links.self=" & child.Item("_links").Item("self").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.status=" & child.Item("channel").Item("status").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.logo=" & child.Item("channel").Item("logo").ToString() & "<br>"
lblMensagemSucesso.Text &= "<img src='" & child.Item("channel").Item("logo").ToString() & "'/><br>"
lblMensagemSucesso.Text &= "channel.video_banner=" & child.Item("channel").Item("video_banner").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.url=" & child.Item("channel").Item("url").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.views=" & child.Item("channel").Item("followers").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel._links.self=" & child.Item("channel").Item("_links").Item("self").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel._links.teams=" & child.Item("channel").Item("_links").Item("teams").ToString() & "<br>"
lblMensagemSucesso.Text &= "<br>"
Next
'Console.ReadLine()
End If
End If
Related
I have a piece of code which will show a list of service areas and, then, when you select a service area it will bring back a list of departments in the second dropdown box. I have the following code:
<%# Language="VBScript"%>
<% response.Buffer = TRUE
'Defines the variables and objects
dim ADUser, RecordList, intOne, intTwo, intThree, companies, service_area, department, arrComp
'Assigns the objComp and objDept variables to Scripting Dictionary objects
%>
<!--#include file="includes/functions.asp"-->
<!--#include file="includes/display.asp"-->
<!--#include file="includes/results.asp"-->
<!--#include file="includes/timer.asp"-->
<h1>Organisational Structure</h1>
<div class="commandspace">
<p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
</div>
<%
ADUser = "LDAP://RBCTHDC1/OU=Staff,OU=Users,DC=example,DC=internal"
' Make AD connection and run query
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.provider ="ADsDSOObject"
objCon.Properties("User ID") = "DOMAIN\username"
objCon.Properties("Password") = "Password"
objCon.Properties("Encrypt Password") = TRUE
objCon.open "Active Directory Provider"
Set objCom = CreateObject("ADODB.Command")
Set objCom.ActiveConnection = objCon
objCom.CommandText ="select company FROM '"& ADUser &"' where company ='*'"
Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
companies = objRS.GetRows()
set arrComp = Server.CreateObject("Scripting.Dictionary")
for intOne = 0 to UBound(companies,2)
if not arrComp.exists(companies(0, intOne)) then
arrComp.add companies(0, intOne), companies(0, intOne)
end if
next
response.write "<form action='index.asp?View=Structure' method='POST'>"
response.write "<select id='service_area' name='service_area' onChange='showTeams(this.value)'>"
response.write "<option>Please Select</option>"
for intTwo = 0 to arrComp.Count
response.write "<option value='"& Server.URLEncode(arrComp.Item(intTwo)) &"'>" & arrComp.Item(intTwo) & "</option>" & VBCrlF
next
response.write "</select>" & VBCrlF
response.write "<span class='structure-spacing'></span>" & VBCrlF
response.write "<select id='department' name='department'></select>" & VBCrlF
response.write "<span class='structure-spacing'></span>" & VBCrlF
response.write "<input type='submit' name='submit' id='submit'>" & VBCrlF
response.write "</form>" & VBCrlF
if request.form("submit")="Submit" then
service_area = request.form("service_area")
department = request.form("department")
if service_area = "Please Select" then
response.write "<p>Service area cannot be left empty</p>"
end if
if IsEmpty(department) then
response.write "<p>Department cannot be left empty</p>"
end if
objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where department = '" & department & "' ORDER BY department"
else
objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where company ='*' ORDER BY department"
end if
Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
RecordList = objRS.GetRows()
response.write "<table>" & VBCrlF
response.write "<thead>" & VBCrlF
response.write "<tr>" & VBCrlF
response.write "<th>Service Area</th>" & VBCrlF
response.write "<th>Department</th>" & VBCrlF
response.write "<th>Job Title</th>" & VBCrlF
response.write "<th>Name</th>" & VBCrlF
response.write "</tr>" & VBCrlF
response.write "</thead>" & VBCrlF
response.write "<tbody>" & VBCrlF
for intThree = 0 to UBound(RecordList,2)
response.write "<tr>" & VBCrlF
response.write "<td>" & RecordList(3, intThree) & "</td>" & VBCrlF
response.write "<td>" & RecordList(2, intThree) & "</td>" & VBCrlF
response.write "<td>" & RecordList(1, intThree) & "</td>" & VBCrlF
response.write "<td>" & RecordList(0, intThree) & "</td>" & VBCrlF
response.write "</tr>" & VBCrlF
next
response.write "</tbody>" & VBCrlF
response.write "</table>" & VBCrlF
objRS.Close
objCon.Close
Set objCon = Nothing
Set objCom = Nothing
%>
I can't find a way of removing duplicate entries. Using a Scripting Dictionary, I am getting an empty drop down box. Instead of returning a list of service area, it doesn't return anything - just an empty option value
Scenario:
I have a SQL database table with Questions. I have another database table that stores the AnswerID, QuestionID and AnswerText.
I would like to list the questions and then show the possible answers in a drop down choice.
I am debating on trying to loop through each question in the Questions table then add a drop down list or create a data grid view with drop down options to choose from.
Must be able to then store the UserID and AnswerID to another table so that the user can view the answers to completed questions in the future.
I am just not sure what angle to take it; either continue with my current thinking of code or try to complete the task within a data grid view.
Function ShowQuestions()
' Pull the data for the base in this query and put in DataSet
Dim QuestionData As System.Data.DataSet
QuestionData = Global.ASP.Global.SQLSelect("SELECT * FROM Questions WHERE Inactive = 'False' ORDER BY QuestionTypeID", "Proposal")
lblQuestionCount.Text = QuestionData.Tables(0).Rows.Count
Dim i As Integer = 0
QuestionHTML &= "<div id='pnlQuestionDetails_" & i & "'>"
QuestionHTML &= "<table width='100%' align='center'>"
QuestionHTML &= "<tr>"
QuestionHTML &= "<td style='text-align:right; width:15%'><h3># </h3></td>"
QuestionHTML &= "<td style='text-align:left; width:50%'><h3> Question Text</h3></td>"
QuestionHTML &= "<td style='text-align:center; width:35%'><h3>Question Answers</h3></td>"
QuestionHTML &= "</tr>"
For Each dr As System.Data.DataRow In QuestionData.Tables(0).Rows
'Dim AnswerID As Integer
'Dim SQLString As String = "SELECT AnswerID, AnswerText FROM QuestionAnswersLink WHERE QuestionID = " & QuestionData.Tables(0).Rows(i)("QuestionID")
'Global.ASP.Global.refresh_ddProposal(AnswerID, SQLString, ddAnswer & i)
QuestionHTML &= "<tr>"
QuestionHTML &= "<td colspan='3'>"
QuestionHTML &= "<hr width='90%'>"
QuestionHTML &= "</td></tr>"
QuestionHTML &= "<tr>"
QuestionHTML &= "<td style='text-align:right'>" & i + 1 & ". </td>"
QuestionHTML &= "<td style='text-align:left'>" & QuestionData.Tables(0).Rows(i)("QuestionText") & "</td>"
QuestionHTML &= "<td style='text-align:center'>drop down list here"
QuestionHTML &= "</td>"
QuestionHTML &= "</tr>"
i = i + 1
Next
QuestionHTML &= "</table>"
QuestionHTML &= "</div>"
Return QuestionHTML
End Function
In html table->tr->td I have <%= ShowQuestions() %>
I may be barking up the wrong tree with my original code, so any direction on what I should use is much appreciated.
How do I get my Asp.net webapi to return the correct response for a pdf form submit?
To keep the response inside of the pdf application you must return an FDF formatted file.
The key to get this to work is that you cannot just return a string. You must first encode it to a memory stream and the header must be set to application/vnd.fdf.
Here is the example code:
Public Function PostValue(<FromBody()> ByVal value As MyPDFFieldsObject) As HttpResponseMessage
Dim fdfmessage As String = "%FDF-1.2" & vbCrLf & _
"1 0 obj <<" & vbCrLf & _
"/FDF <<" & vbCrLf & _
"/Status (Submitted Successfully!)" & vbCrLf & _
">>" & vbCrLf & _
">>" & vbCrLf & _
"endobj" & vbCrLf & _
"trailer" & vbCrLf & _
"<</Root 1 0 R>>" & vbCrLf & _
"%%EOF"
Dim result As HttpResponseMessage = New HttpResponseMessage(HttpStatusCode.OK)
Dim stream As New MemoryStream(Encoding.UTF8.GetBytes(fdfmessage))
stream.Position = 0
result.Content = New StreamContent(stream)
result.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.fdf")
Return result
End Function
I tried everything, but nothing seems to work!
How the do I put a breakline?!
Dim textMsg as String
textMsg = Body.text & Environment.Newline & _ q1.text & Environment.Newline & _ q2.text & Environment.Newline & _ q3.text & Environment.Newline & _ q4.text '
please help
(with corrent code I get an error cuz of the & Environment.Newline & _ ")
Since you tagged this asp.net, I'll guess that this newline should appear in a web page. In that case, you need to remember that you are creating html rather than plain text, and html ignores all whitespace... including newlines. If you view the source for your page, you'll likely see that the new lines do make it to your html output, but they are ignored, and that's what is supposed to happen. If you want to show a new line in html, use a <br> element:
textMsg = Body.text & "<br>" & _ q1.text & "<br>" & _ q2.text & "<br>" & _ q3.text & "<br>" & _ q4.text
The code above will place the text on several lines. It's interesting that if you view the source now, you'll see that everything is all on the same line, even though it uses several lines for display.
You should add a br:
textMsg = Body.text & "<BR/>" & _ q1.text & "<BR/>" & _ q2.text & "<BR/>" & _ q3.text & "<BR/>" & _ q4.text
Or you can try:
Str & VBNewLine OR Str & VBCrLf
Or set the email message to html. The the will work.
thats the right one:
& (vbCrLf) &
Try this:
dim textMsg as String
textMsg = Body.text & vbNewLine
I preffer .Net Style:
& Environment.NewLine &
It's Is exactly the same that
& (vbCrLf) &
I'm using ASP.Net to output HTML/XML data so that it can be opened by MS Excel. The idea of course is to be able to send any tabular data to Excel. I have it working, but really want to implement a freeze pane on the top row for the column headings. From what I have read it's possible, and I've tried to implement bits of code I've seen, but still no dice, and I've found very little good reading on this.
Here's a similar post. I'm actually implementing the suggested code.
How to freeze the header row in an Excel spreadsheet exported from ASP.NET
Here's the code used to generate the output:
Dim html_response As String = ""
html_response &= "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">" & vbCrLf
html_response &= "<head>" & vbCrLf
html_response &= " <meta http-equiv=""Content-Type"" content=""text/htmlcharset=windows-1252"">" & vbCrLf
html_response &= " <!--[if gte mso 9]>" & vbCrLf
html_response &= " <xml>" & vbCrLf
html_response &= " <x:ExcelWorkbook>" & vbCrLf
html_response &= " <x:ExcelWorksheets>" & vbCrLf
html_response &= " <x:ExcelWorksheet>" & vbCrLf
html_response &= " <x:Name>WorkSheet Name</x:Name>" & vbCrLf
html_response &= " <x:WorksheetOptions>" & vbCrLf
html_response &= " <x:Selected/>" & vbCrLf
html_response &= " <x:FreezePanes/>" & vbCrLf
html_response &= " <x:FrozenNoSplit/>" & vbCrLf
html_response &= " <x:SplitHorizontal>1</SplitHorizontal>" & vbCrLf
html_response &= " <x:TopRowBottomPane>1</TopRowBottomPane>" & vbCrLf
html_response &= " <x:Panes>" & vbCrLf
html_response &= " <x:Pane>" & vbCrLf
html_response &= " <x:Number>3</x:Number>" & vbCrLf
html_response &= " <x:Pane>" & vbCrLf
html_response &= " <x:Pane>" & vbCrLf
html_response &= " <x:Number>2</x:Number>" & vbCrLf
html_response &= " <x:Pane>" & vbCrLf
html_response &= " </x:Panes>" & vbCrLf
html_response &= " <x:ActivePane>2</x:ActivePane>" & vbCrLf
html_response &= " <x:ProtectContents>False</x:ProtectContents>" & vbCrLf
html_response &= " <x:ProtectObjects>False</x:ProtectObjects>" & vbCrLf
html_response &= " <x:ProtectScenarios>False</x:ProtectScenarios>" & vbCrLf
html_response &= " </x:WorksheetOptions>" & vbCrLf
html_response &= " </x:ExcelWorksheet>" & vbCrLf
html_response &= " </x:ExcelWorksheets>" & vbCrLf
html_response &= " </x:ExcelWorkbook>" & vbCrLf
html_response &= " </xml>" & vbCrLf
html_response &= " <![endif]-->" & vbCrLf
html_response &= "</head>" & vbCrLf
html_response &= "<body>" & vbCrLf
'Tabular data retrieved from Session var
html_response &= table_data
html_response &= "</body>" & vbCrLf
html_response &= "</html>" & vbCrLf
'Browser/header stuff
Dim filename As String = Session("UserLoggedIn") & "_" & DateTime.Now().ToFileTime() & ".xls"
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment filename=" & filename)
Response.Write(html_response)
And here's a picture showing what I get each time in Excel (I'm using Excel 2007):
As you can see, Excel is consuming the data, but no freeze pane at the top, AND it appears that some of the XML WorkSheetOptions variables are being printed in cell A1.
NOTE: I have almost no idea how the panes and their numbers play into all this, and I'm having a terrible time finding documentation. I'd be glad to read and learn if I could find something.
Any idea what I'm doing wrong here?
EDIT: Thought I would post what finally solved my issue, in case some other poor soul needs it. Only took an entire day of fiddling around.
This first function prepares the final XML for export via Response.Write, which is opened on the client machine in Excel, if they have it installed.
Public Shared Function FormatBasicSpreadsheet(excel_table_data As String, worksheet_name As String) As String
Dim html As String = ""
'The first two lines make sure Windows opens this document with Excel
html &= "<?xml version=""1.0""?>" & vbCrLf
html &= "<?mso-application progid=""Excel.Sheet""?>" & vbCrLf
html &= "<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet""" & vbCrLf
html &= " xmlns:o=""urn:schemas-microsoft-com:office:office""" & vbCrLf
html &= " xmlns:x=""urn:schemas-microsoft-com:office:excel""" & vbCrLf
html &= " xmlns:ss=""urn:schemas-microsoft-com:office:spreadsheet""" & vbCrLf
html &= " xmlns:html=""http://www.w3.org/TR/REC-html40"">" & vbCrLf
'Add styling for rows/cells
html &= "<Styles>" & vbCrLf
html &= " <Style ss:ID=""Default"" ss:Name=""Normal"">" & vbCrLf
html &= " <Alignment ss:Vertical=""Bottom""/>" & vbCrLf
html &= " <Borders/>" & vbCrLf
html &= " <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000""/>" & vbCrLf
html &= " <Interior/>" & vbCrLf
html &= " <NumberFormat/>" & vbCrLf
html &= " <Protection/>" & vbCrLf
html &= " </Style>" & vbCrLf
html &= " <Style ss:ID=""header_bold"">" & vbCrLf
html &= " <Alignment ss:Vertical=""Bottom"" ss:WrapText=""0""/>" & vbCrLf
html &= " <Font ss:FontName=""Calibri"" x:Family=""Swiss"" ss:Size=""11"" ss:Color=""#000000"" ss:Bold=""1""/>" & vbCrLf
html &= " <Borders>" & vbCrLf
html &= " <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " </Borders>" & vbCrLf
html &= " <Interior ss:Color=""#F2F2F2"" ss:Pattern=""Solid""/>" & vbCrLf
html &= " </Style>" & vbCrLf
html &= " <Style ss:ID=""all_borders"">" & vbCrLf
html &= " <Borders>" & vbCrLf
html &= " <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>" & vbCrLf
html &= " </Borders>" & vbCrLf
html &= " <Interior ss:Color=""#F2F2F2"" ss:Pattern=""Solid""/>" & vbCrLf
html &= " </Style>" & vbCrLf
html &= "</Styles>" & vbCrLf
html &= "<Worksheet ss:Name=""" & worksheet_name & """>" & vbCrLf
'Tabular retrieved from Session var
'NOTE: MUST be in proper Excel XML table format.
html &= excel_table_data & vbCrLf
'Worksheet options - freeze panes, etc.
html &= "<WorksheetOptions xmlns=""urn:schemas-microsoft-com:office:excel"">" & vbCrLf
html &= " <Selected/>" & vbCrLf
html &= " <FreezePanes/>" & vbCrLf
html &= " <FrozenNoSplit/>" & vbCrLf
html &= " <SplitHorizontal>1</SplitHorizontal>" & vbCrLf
html &= " <TopRowBottomPane>1</TopRowBottomPane>" & vbCrLf
html &= " <ActivePane>2</ActivePane>" & vbCrLf
html &= " <Panes>" & vbCrLf
html &= " <Pane>" & vbCrLf
html &= " <Number>3</Number>" & vbCrLf
html &= " </Pane>" & vbCrLf
html &= " <Pane>" & vbCrLf
html &= " <Number>2</Number>" & vbCrLf
html &= " <ActiveRow>0</ActiveRow>" & vbCrLf
html &= " </Pane>" & vbCrLf
html &= " </Panes>" & vbCrLf
html &= " <ProtectObjects>False</ProtectObjects>" & vbCrLf
html &= " <ProtectScenarios>False</ProtectScenarios>" & vbCrLf
html &= "</WorksheetOptions>" & vbCrLf
html &= "</Worksheet>" & vbCrLf
html &= "</Workbook>" & vbCrLf
Return html
End Function
Hopefully, this might help someone down the road. Cheers.
Here's a function for formatting Excel XML table data, the result of which is fed to the function above.
Public Shared Function CreateExcelXmlTableFromSQL(ByVal SQL As String, IncludeHeaderStyling As Boolean) As String
Dim html As String = ""
'These variables are for setting the column width declarations
Dim column_width_template As String = "<Column ss:Width=""$$$""/>"
Dim column_character_pixel_constant As Single = 5.5 'Pixels per character
Dim column_list As New Generic.Dictionary(Of Int32, Int32)
'Open dbase connection
Dim conn As SqlConnection = dbase.CreateSqlConnection()
'Fill the datareader
Dim dr As SqlDataReader = dbase.ReturnDataReader(conn, Sql)
'Check the datareader
If (dr Is Nothing) OrElse (dr.IsClosed) Then
Return ""
End If
'Begin the table
html &= "<Table>" & vbCrLf
'Put columns placeholder in
html &= "[COLUMNS]" & vbCrLf
'NOTE: The datareader object (unlike the old ADODB recordset) is forward only. This means
' means that there is no reset of the pointer. When you read the first row to get
' the column names, you MUST also generate the first row of content, or you'll be missing
' one row.
'Read the first row of the datareader for the column headings, PLUS the first row of data.
While (dr.Read)
'Write table headers
'NOTE: This contains XML style tags
Dim header_row_style As String = " ss:StyleID=""all_borders"""
Dim header_cell_style = " ss:StyleID=""header_bold"""
If (Not IncludeHeaderStyling) Then
header_row_style = ""
header_cell_style = ""
End If
html &= "<Row" & header_row_style & ">" & vbCrLf
For i As Int16 = 0 To dr.FieldCount - 1
'NOTE: you see the styleID I included here. In billing_export_report where I
'build the overall Excel XML doc, I define this.
html &= "<Cell" & header_cell_style & "><Data ss:Type=""String""> " & dr.GetName(i) & "</Data></Cell>" & vbCrLf
column_list.Add(i, dr.GetName(i).Length)
Next
html &= "</Row>" & vbCrLf
'Write the first row of data
html &= "<Row>" & vbCrLf
For i As Int16 = 0 To dr.FieldCount - 1
html &= "<Cell><Data ss:Type=""String""> " & dr(i).ToString() & "</Data></Cell>" & vbCrLf
If (column_list.Item(i) < dr(i).ToString().Length) Then
column_list.Item(i) = dr(i).ToString().Length
End If
Next
html &= "</Row>" & vbCrLf
'Exit this loop after first row
Exit While
End While
'Write the content, starting at the second row, switching row colors.
While (dr.Read)
'Start row
html &= "<Row>" & vbCrLf
'Write the row contents
For i As Int16 = 0 To dr.FieldCount - 1
html &= "<Cell><Data ss:Type=""String""> " & dr(i) & "</Data></Cell>" & vbCrLf
If (column_list.Item(i) < dr(i).ToString().Length) Then
column_list.Item(i) = dr(i).ToString().Length
End If
Next
html &= "</Row>" & vbCrLf
End While
html &= "</Table>" & vbCrLf
'Now put the column declarations in, so that
'the widths are correct.
Dim columns_html As String = ""
For Each k As Generic.KeyValuePair(Of Int32, Int32) In column_list
Dim pixel_value As Single = (k.Value * column_character_pixel_constant) + 10
columns_html &= column_width_template.Replace("$$$", pixel_value.ToString()) & vbCrLf
Next
html = html.Replace("[COLUMNS]", columns_html)
dr.Close()
dr = Nothing
conn.Close()
conn.Dispose()
conn = Nothing
'Return the completed table
Return html
End Function
Here's an image of the finished Excel exported via Response.Write. You can see it has styling of the header row, freeze pane works, and column widths are set for proper display.
Finally discovered a workable solution. I posted details in the original question area above.