Er. Manish Insan
unread,Feb 2, 2011, 3:51:08 AM2/2/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DotNetProfessionals-Group
----------------------------------Add this namespace:-----
using Excel3 = Microsoft.Office.Interop.Excel;
------------------------------------Add this dll file using “add
reference” :------
Microsoft.Office.Interop.Excel version 12.000
Write this on button click event :----
Excel3.ApplicationClass excel = new Excel3.ApplicationClass();
excel.Application.Workbooks.Add(true);
int ColumnIndex = 0;
foreach (GridView col in GridView1.Columns)
{
ColumnIndex++;
excel.Cells[1, ColumnIndex] = col.Caption;
excel.Cells[1, ColumnIndex] = col.Caption;
}
int rowIndex = 0;
foreach (GridViewRow row in GridView1.Rows)
{
rowIndex++;
ColumnIndex = 0;
foreach(TableCell cell in row.Cells)
{
ColumnIndex++;
excel.Cells[rowIndex + 1, ColumnIndex] = cell.Text;
}
}
excel.Visible = true;
Excel3.Worksheet worksheet =
(Excel3.Worksheet)excel.ActiveSheet;
worksheet.PageSetup.Orientation =
Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
worksheet.Columns.ColumnWidth = 7;
worksheet.PageSetup.CenterHeader = "Fee Collection Summary";
worksheet.PageSetup.CenterFooter = "Soft By LIo
Technologies";
worksheet.Cells.Font.Bold = false;