1)把数据导出excel
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
/// <summary>
/// 把数据导入Excel中
/// </summary>
private void ExcelExport(UltraGrid ultraGrid)
{
try
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
// 设置默认文件扩展名
saveFileDialog.DefaultExt = "Microsoft Excel 工作表.xls";
// 设置文件筛选器字符串
saveFileDialog.Filter = "Microsoft Excel 工作表(*.xls)|*.xls";
// 设置对话框显示的初始目录
saveFileDialog.InitialDirectory = @"C:\Documents and Settings";
// 运行具有指定所有者的通用对话框
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
// 获取保存地址及文件名
string path = saveFileDialog.FileName;
// Excel导出
excelExporter.Export(ultraGrid, path);
MessageBox.Show("导出成功!", "Excel导出", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (System.IO.IOException ex)
{
MessageBox.Show(ex.Message, "Excel导出", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("导出失败!" + ex.Message, "Excel导出", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
posted @
2009-09-27 12:59
xumingming
阅读(
396)
评论()
编辑
收藏
举报