The HTML Agility Pack is an HTML parser for .NET, supporting XPATH and XSLT parsing. Basically the HTML equivalent of XmlDocument . Example use (from site): HtmlDocument doc = new HtmlDocument(); doc.Load("file.htm"); foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href]") { HtmlAttribute att = link["href"]; att.Value = FixLink(att); } doc.Save("file.htm");
The 'correct' way to generate Excel spreadsheets is through the use of Office Web Components . However, due to the licensing (see MSKB Article ) you cannot use them on a public internet site (as a client license for Office is needed for each user retrieving the document).
However, this can be overcome due to the fact that Excel recognises HTML code. You can therefore output HTML that can be opened in Excel:
First of all, set the content type and response header to make the browser handle it as an Excel spreadsheet.
ASP VBScript:
<%@Language="VBScript"%>
<%
Response.ContentType="application/vnd.ms-excel"
Response.AddHeader "content-disposition", "attachment; filename=ExcelFileName"
%>
ASP JScript:
<%@Language="JScript"%>
<%
Response.ContentType="application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=ExcelFileName");
%
Update: Added VB code. There may be some cases where you want a DropDownList to list all the letters in the alphabet (i.e. A - Z). Rather than add the letter individually (through using <asp:ListItem> ) you can create an ArrayList and bind to that. In your ASPX page: <asp:DropDownList ID="Letters" DataSource='<%# Alphabet %>' runat="server" /> In your code behind. Create your Alphabet property: private ArrayList _Alphabet; protected ArrayList Alphabet { get { if (_Alphabet == null) { _Alphabet = new ArrayList(); for (int i = 65; i < 91; i++) { _Alphabet.Add(Convert.ToChar(i)); } } return _Alphabet; } } Protected ReadOnly Property Alphabet() As ArrayList Get If _Alphabet Is Nothing Then _Alphabet = New ArrayList() For i As Integer = 65 To 91 - 1 _Alphabet.Add(Convert.ToChar(i)) Next End If Return _Alphabet End Get End Property Bind on Page_Load: private void Page_Load(object sender
Comments
Changed the following:
var option = document.createElement("option");
option.value = value;
option.text = text;
this.options.add(option);
to
var option = document.createElement("option"); if($.browser.mozilla){
option.value = value;
option.text = text;
this.options.add(option);
} else {
this.add(option);
option.innerText = text;
option.value = value;
}