Results 1 to 3 of 3

Thread: How do i transfer html form data to excel

  1. #1
    Join Date
    Jan 2009
    Posts
    92

    How do i transfer html form data to excel

    I'm having many html forms, on which i had saved some personal data on it. Now, i would like to transfer that data on my Excel sheet. Can any body provide me the correct solution for the above issue? Have any body transfer their Html forms data to Excel sheet? Kindly provide me the solution for teh above issue.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How do i transfer html form data to excel

    Hey you can try the following code in order to transfer your Html form data to Excel sheet.

    DataSet ds=objAdmin.getErrorsInDetail();
    Response.AppendHeader("Content-Disposition", "attachment; filename=Error.xls") ;
    Response.ContentType="application/ms-excel";

    Response.Write("<table>");
    Response.Write("<tr>");
    for(int i=0;i<ds.Tables[0].Columns.Count;i++)
    {
    Response.Write("<td>"+ ds.Tables[0].Columns[i].ColumnName +"</td>");
    }
    Response.Write("</tr>");
    for(int i=0;i<ds.Tables[0].Rows.Count;i++)
    {
    Response.Write("<tr>");
    DataRow row=ds.Tables[0].Rows[i];
    for(int j=0;j<ds.Tables[0].Columns.Count;j++)
    {

    Response.Write("<td>"+ row[j]+"</td>");
    }
    Response.Write("</tr>");
    }
    Response.Write("</table>");
    Response.End();

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How do i transfer html form data to excel

    The XML file that is generated can be opened directly in Excel. For illustration purposes, the DataSet object is created from the Microsoft Access Northwind sample database by using the Jet OLEDB Provider. However, similar code works with any DataSet object that you create with Visual C# 2005 or Visual C# .NET.

    1. Start Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET. On the File menu, click New and then click Project. Select Windows Application from the Visual C# Projects types. Form1 is created by default.
    2. On the View menu, select Toolbox to display the Toolbox and add a button to Form1.
    3. Double-click Button1. The code window for the Form appears.
    4. Add the following using directives to the top of Form1.cs:
    using System.Data.OleDb;
    using System.Xml;
    5. Add the following private member variable to the Form1 class:
    private string strConn ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    + " C:\\Program Files\\Microsoft Office\\Office10\\Samples\\"
    + "Northwind.mdb;";
    Note You may need to modify the path to Northwind.mdb in the connection string to match your installation.

    6. Add the following code to the button1_Click handler:

    //Connect to the data source.
    OleDbConnection objConn = new OleDbConnection (strConn);
    try
    {
    objConn.Open();

    //Fill a dataset with records from the Customers table.
    OleDbCommand objCmd = new OleDbCommand(
    "Select CustomerID, CompanyName, ContactName, "
    + "Country, Phone from Customers", objConn);
    OleDbDataAdapter objAdapter = new OleDbDataAdapter();
    objAdapter.SelectCommand = objCmd;
    DataSet objDataset = new DataSet();
    objAdapter.Fill(objDataset);

    //Create the FileStream to write with.
    System.IO.FileStream fs = new System.IO.FileStream(
    "C:\\Customers.xml", System.IO.FileMode.Create);
    //Create an XmlTextWriter for the FileStream.
    System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(
    fs, System.Text.Encoding.Unicode);
    //Add processing instructions to the beginning of the XML file, one
    //of which indicates a style sheet.
    xtw.WriteProcessingInstruction("xml", "version='1.0'");
    //xtw.WriteProcessingInstruction("xml-stylesheet",
    // "type='text/xsl' href='customers.xsl'");

    //Write the XML from the dataset to the file.
    objDataset.WriteXml(xtw);
    xtw.Close();

    //Close the database connection.
    objConn.Close();
    }
    catch (System.Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    Note You must change the code in Visual Studio 2005. By default, Visual C# adds one form to the project when you create a Windows Forms project. The form is named Form1. The two files that represent the form are named Form1.cs and Form1.designer.cs. You write the code in Form1.cs. The Form1.designer.cs file is where the Windows Forms Designer writes the code that implements all the actions that you performed by dragging and dropping controls from the Toolbox.

    7. Press F5 to build and run the program.
    8. Click Button1 to create the XML file, then close Form1 to end the program.
    9. Start Excel 2002 or Excel 2003 and open the C:\Customers.xml output file.
    10. After you have observed how the XML has been parsed into rows and columns in the new workbook, close the file and quit Excel.

Similar Threads

  1. Replies: 5
    Last Post: 25-05-2011, 10:21 PM
  2. transfer data Between excel sheets
    By kvirmani in forum MS Office Support
    Replies: 1
    Last Post: 21-04-2011, 05:34 PM
  3. Transfer data between sheets in excel
    By Shanbaag in forum Windows Software
    Replies: 3
    Last Post: 16-10-2009, 10:40 AM
  4. Convert Excel data to HTML Table
    By Chalina in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 11:21 PM
  5. Insertion of clean Excel data into oracle table using html
    By Valerian in forum Software Development
    Replies: 3
    Last Post: 13-06-2009, 09:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,781,566.06782 seconds with 16 queries