Click here to Skip to main content
15,917,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wanted to export data from grid view to my own format excel sheet.I have a code to export to a new workbook,but i`m getting problem with exporting to our companies standard excel sheet format that already contain header,footer and body design.Please help with code how to add data from grid view to existing file??

Here is my code in button_Click event:

Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
Workbook vb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;


xla.Visible = true;

ws.Cells[1, 1] = "Slno";
ws.Cells[1, 2] = "code";
ws.Cells[1, 3] = "name";


ws.Cells[2, 1] = TextBox1.Text;
ws.Cells[2, 2] = TextBox2.Text;
ws.Cells[2, 3] = TextBox3.Text;
Posted
Comments
manognya kota 14-Jan-12 4:04am    
hi,

I guess you can write into the standard excel instead of creating a new excel.
See the below link to write to excel..

http://social.msdn.microsoft.com/Forums/da-DK/csharpgeneral/thread/ef11a193-54f3-407b-9374-9f5770fd9fd7[^]


Hope this works out...

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