Import data in Excel From Web Page

8 views
Skip to first unread message

Er. Manish Insan

unread,
Feb 2, 2011, 3:51:08 AM2/2/11
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;





Reply all
Reply to author
Forward
0 new messages