Web Design & Development

Web Form Data Spreadsheet Download

Tagged with: , ,

Usually, a website owner has the data from their contact forms emailed to them.  But sometimes it can be useful for the site to automatically add that info to an ongoing list of contacts.  One way that most people like to be able to see and sort such data is in a spreadsheet.  It is quite easy to make a “fake” spreadsheet using an HTML table that Excel will open like any other .xls file.

Here are the basic steps:

    • Create and save a “spreadsheet” that defines the header row
    • Upon each contact form submittal, write an HTML row to that file 

You can use a simple text editor, such as notepad, to create the “.xls header file” that is ready to accept new data rows. Also shown below are some code snippets to add to the webform and the code behind the page. 

In the contacts.xls file (initially):

<html xmlns:o=”urn:schemas-microsoft-com:office:office”



<!–[if gte mso 9]><xml>























<tr style=”font-weight:bold; text-align:center;”>


<td>First Name</td>

<td>Last Name</td>




In the contact-us.aspx file:

First Name: <asp:TextBox runat=”server” ID=”txtFirstName” /><br />

Last Name: <asp:TextBox runat=”server” ID=”txtLastName” /><br />

Email: <asp:TextBox runat=”server” ID=”txtEmail” /> <br />

Phone: <asp:TextBox runat=”server” ID=”txtPhone” /><br />

In the contact-us.aspx.cs file:

    protected void SaveData()


        String strFilePath = Server.MapPath(“contacts.xls”);

        if (File.Exists(strFilePath))


            StreamWriter objSW = new StreamWriter(strFilePath, true);   // true = append


            objSW.WriteLine(“<td>” + DateTime.Now + “</td>”);

            objSW.WriteLine(“<td>” + txtFirstName.Text + “</td>”);

            objSW.WriteLine(“<td>” + txtLastName.Text + “</td>”);

            objSW.WriteLine(“<td>” + txtEmail.Text + “</td>”);

            objSW.WriteLine(“<td>” + txtPhone.Text + “</td>”);





Then all you have to do is link to that .xls file and Excel will open it right up. 

Note: Your server permissions may need to change to allow your site to write to files. Also remember that unless you write your “.xls” into a secure area, then it will be a publicly available file.