Hi All,
I have following Requirement please can anybody help me.
i have excel file with predefined template as follows with Emp.xls
EID (B5): EName(D5):
Designation(B6):
Now i created webform with the following textboxes
txtEID, txtName & txtDesignation with Submit button
now my requirement is If i click submit button
the values which is taken from the user through textboxes will be copied into the
following positions in the emp.xls file such as
txtEID value-----> C5cell in Excel file
txtName value --->E5cell in Excel file
txtDesignation value--> B6cell in Excel file
and the excel file has to save in some location with the filename of with Emp_EID(ID may vary to employee by employee)
how can i achieve this...
Loading

SIVAPosted Jan 4, 2012, 11:35 AM
Satyapriya NayakPosted Jan 4, 2012, 10:04 AM
So when you will insert the records it will go on adding to it.
I think your requirement is different.
SIVAPosted Jan 4, 2012, 9:56 AM
Satyapriya NayakPosted Jan 4, 2012, 9:12 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
string str;
protected void Button1_Click(object sender, EventArgs e)
{
try
{
com = new OleDbCommand();
con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("test.xls") + ";Extended Properties=Excel 8.0");
con.Open();
com.Connection = con;
str = "Insert into [sheet1$] (EID,EName,Designation) values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";
com.CommandText = str;
com.ExecuteNonQuery();
con.Close();
Response.Write("Records Added Successfully");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
Thanks