.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Creation of excel through coding

Posted By: nishithraj     Posted Date: November 26, 2009    Points:2   Category :ASP.Net
I have the following requirements.

1) I need to create an excel with locked/unlocked fields. It has to be created based on the database values(if there are 10 rows in the data base the excel will have 10 rows with answer column)
2) User can download and fill the answer column. He should not be able to edit the locked fields.
3) He can export it to the application. That means, I need to read the data and export it to data base
4) All the above should work even there is no MS office in the installed server.

Excel component is not the right answer. Because it fails if there is no office in the installed machine.

Any other components??? It should be free to use.

Responses
Author: Syed Shakeer Hussain             
Posted Date: November 29, 2009     Points: 5   

Hi nishitraj,
Below is the code for creating Excel sheet and Exporting data from Gridview to Excelsheel with Ms OFFICE installation.
In the same way you can send data from database table to Excel Sheet:-
//Double click your Button and write the below code to Export Gridview Data to Excel

protected void Button1_Click(object sender, EventArgs e)

{

TextWriter sw = new StreamWriter(@"F:\\ExcelData.xls");

//Getting the Gridview HeaderRow Values

sw.WriteLine(GridView1.HeaderRow.Cells[0].Text+"\t"+GridView1.HeaderRow.Cells[1].Text+"\t"

+GridView1.HeaderRow.Cells[2].Text);



for (int i = 0; i < GridView1.Rows.Count; i++)

{

//Getting the Gridview Row values

sw.WriteLine(GridView1.Rows[i].Cells[0].Text + "\t " + GridView1.Rows[i].Cells[1].Text + "\t" + GridView1.Rows[i].Cells[2].Text );

}

sw.Close();//Don't Forget to Close the StreamWrtier object.


}
}

I wrote Article on this type.you can read in my artciles with Iamges.

Author: nishithraj             
Posted Date: November 30, 2009     Points: 5   

Hi syed,

Thanks for the information. Can you share the link for the article....



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend