Winform下datagrid数据倒入excel
2005-10-20 16:52
387 查看
Excel.Application excel = new Excel.Application ( ) ;
excel.Application.Workbooks.Add ( true ) ;
for(int n =0;n<dt.Columns.Count;n++)
{
excel.Cells[1,n+1] = dt.Columns
.ColumnName;
}
for(int i=0;i<dt.Rows.Count;i++)
{
for(int j=0;j<dt.Columns.Count;j++)
{
excel.Cells[i+2,j+1] = dt.Rows[i][j].ToString();
}
}
Excel.Range r1 = excel.get_Range(excel.Cells[1,1],excel.Cells[dt.Rows.Count+1,dt.Columns.Count]);
r1.EntireColumn.AutoFit();
r1.EntireRow.AutoFit();
r1.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
r1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
excel.Visible = true ;
excel.Application.Workbooks.Add ( true ) ;
for(int n =0;n<dt.Columns.Count;n++)
{
excel.Cells[1,n+1] = dt.Columns
.ColumnName;
}
for(int i=0;i<dt.Rows.Count;i++)
{
for(int j=0;j<dt.Columns.Count;j++)
{
excel.Cells[i+2,j+1] = dt.Rows[i][j].ToString();
}
}
Excel.Range r1 = excel.get_Range(excel.Cells[1,1],excel.Cells[dt.Rows.Count+1,dt.Columns.Count]);
r1.EntireColumn.AutoFit();
r1.EntireRow.AutoFit();
r1.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
r1.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
excel.Visible = true ;
相关文章推荐
- 在winform开发中如何把datagrid里面的数据导出成EXCEL文件
- 如何将DataGrid中的数据倒入到Excel (客户端)
- DataGrid中的数据倒入Excel
- winform中 将DataGrid中的数据导入Excel中,并显示Excel应用程序
- WinForm中把DataGrid里面的数据导出成EXCEL文件(VB.net)
- winform中 将DataGrid中的数据导入Excel中,并显示Excel应用程序
- Datagrid数据导出到excel文件的三种方法
- winform导出dataviewgrid数据为excel的方法
- 将DataGrid中的数据导出为Excel的方法
- c#读取excel中的数据(winform)
- 将DataGrid数据写入Excel文件,然后下载
- 导出DataGrid中的数据到Excel,Word,Text
- Silverlight 将DataGrid的数据导入到Excel中
- 将DataGrid中数据倒出Excel文件并下载
- excel数据导入到datagrid
- C# Winform实现数据的导出为txt或者CSV或者excel格式
- 导出DataGrid中的数据到Excel
- winform中将数据以文本的格式导出到excel中(以文本导出表示如果数据为0001则在excel中也显示为0001,而不被excel自动转换为1)
- 将ORACLE数据库的数据倒入到EXCEL中的方法
- datagrid数据导出到excel文件给客户端下载的几种方法