Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a doubt related to asp.net c#. I am developing a web project, in which, there is a web form, that has a number of textbox entries and a submit button.

After entering the data in the textboxes and clicking submit button, all the data should be read from the Textboxes and inserted in to an Excel document designed in the form of a "form". The Excel document has texboxes, which need to be populated from the asp.net webform. How is this possible ?

I have a concept in mind :- I will upload a copy of the Excel sheet into the website. When a user fills the form and click on submit, an instance of the Excel document is called, and data is inserted. After that, the Excel sheet instance is renamed as "username" and saved somewhere. Is it possible to create instances of Excel sheets like this ?
Posted

1 solution

Sorry for not doing that.
I could create a new blank instance of the excel spreadsheet, but I don't know how to open an existing file, create a duplicate of that file, insert data and save it in a new name.

The code that I used to write data to a blank file is :-

protected void btnSubmission_Click(object sender, EventArgs e)
{
    Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
    Workbook wb = xlapp.Workbooks.Add(XlSheetType.xlWorksheet);
    Worksheet ws = (Worksheet)xlapp.ActiveSheet;

    xlapp.Visible = true;

    String s1 = TextBox2.Text;
    ws.Cells[4,4]=s1;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900