Advertisement
Advertisement
| 04.09.2008 at 03:41PM PDT, ID: 23309984 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: |
Microsoft.Office.Interop;
private void button1_Click(object sender, EventArgs e)
{
Excel.ApplicationClass excel = new ApplicationClass();
excel.Application.Workbooks.Add(true);
DataTable table = DataSet2.Tables[0];
int ColumnIndex = 0;
foreach (Datacolumn col in table.Columns)
{
ColumnIndex++;
excel.Cells[1, ColumnIndex] = col.ColumnName;
}
int rowIndex = 0;
foreach (DataRow row in table.Row)
{
rowIndex++;
ColumnIndex = 0;
foreach (DataColumn col in table.Columns)
{
ColumnIndex++;
excel.Cells[rowIndex + 1, ColumnIndex] = row.Cells[col.ColumnName].Text;
}
}
excel.Visible = true;
Worksheet worksheet = (Worksheet)excel.ActiveSheet;
worksheet.Activate();
//string strTitle = dataGridView1;
// new DataGridExcelExporter(this.dataGridView1 , this.Page).Export(strTitle);
}
|