Sunday, October 14, 2012

GridView to Excel . . . .



using Microsoft.Office.Interop.Excel;

private void exportButton_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application xApplication = new
Microsoft.Office.Interop.Excel.Application();

Workbook workbook =
xApplication.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet worksheet = (Worksheet)xApplication.ActiveSheet;
xApplication.Visible = true;

for (int i = 1; i < purchaseReportDataGridView.Rows.Count; i++)
{
for (int j = 0; j < 13; j++)
{
worksheet.Cells[i + 1, j + 1] =
purchaseReportDataGridView.Rows[i].Cells[j].Value;
}
}
}

Never hasitate to  comment or ask me.
Happy Codding .......

No comments:

Post a Comment