执行时,怎会弹出一个对话框: 是否保存对“Sheet1”的更改现在,想去点提示框并且默认选择是,然后进行下一步的路径及名称的更改,,并且名称要默认成自己设置的而不是Sheet1public bool ExportByDs(ExcelDTO _ExcelDTO)
{
// 获取文件名
String fileName = _ExcelDTO.fileName; // 获取导出数据源
DataSet ds = _ExcelDTO.ds; // 参数传递不正确的场合,直接返回。
if (ds == null || ds.Tables.Count == 0 || fileName == string.Empty)
{
return false;
} // 新建excel工作薄
Application excel = new Application();
Workbook work = excel.Workbooks.Add(true); System.Data.DataTable table = ds.Tables[0];
int rowindex = 1;
int colindex = 0; // 打印title
foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[1, colindex] = col.ColumnName; } // 打印data
foreach (DataRow row in table.Rows)
{
rowindex++;
colindex = 0; foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();
}
} //Range a = excel.get_Range("A1", "'A'rowindex");
//a.NumberFormatLocal = "@"; excel.Visible = false;
try
{
excel.ActiveWorkbook.SaveCopyAs("fileName");
}
catch (Exception e)
{ }
finally
{
excel.Quit();
excel = null;
GC.Collect();
} return true;
}
{
// 获取文件名
String fileName = _ExcelDTO.fileName; // 获取导出数据源
DataSet ds = _ExcelDTO.ds; // 参数传递不正确的场合,直接返回。
if (ds == null || ds.Tables.Count == 0 || fileName == string.Empty)
{
return false;
} // 新建excel工作薄
Application excel = new Application();
Workbook work = excel.Workbooks.Add(true); System.Data.DataTable table = ds.Tables[0];
int rowindex = 1;
int colindex = 0; // 打印title
foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[1, colindex] = col.ColumnName; } // 打印data
foreach (DataRow row in table.Rows)
{
rowindex++;
colindex = 0; foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();
}
} //Range a = excel.get_Range("A1", "'A'rowindex");
//a.NumberFormatLocal = "@"; excel.Visible = false;
try
{
excel.ActiveWorkbook.SaveCopyAs("fileName");
}
catch (Exception e)
{ }
finally
{
excel.Quit();
excel = null;
GC.Collect();
} return true;
}
解决方案 »
- 求大侠们救命啊,作业做吐血啦,本人新手,简单问题
- asp.net中如何动态加载图片?
- 弹出层设置图片URL问题
- 如何在多个页面中设断点?? 就是A页中设了一个断点,B页中也设了一个断点,A先运行,然后A中展示数据,然后跳转到B页展示数据 ××××××
- ASP.NET前台显示代码的问题?
- 请教一个有关删除的sql语句
- 哪位有javascript编程起步 电子书 100分奉上(只要pdf或chm格式的)
- 一个关于程序集的问题!(相关程序 动网新闻)
- 为什么我的帖子不能给分
- 大家知道如何在一个页面实现多个功能切换
- 有谁用过ExtAspNet的帮帮忙,关于Gird控件gridRow的问题,小弟菜鸟在线等了,急啊!!!!
- MVC3 添加和修改共用一个视图文件
有这句还不行吗?这就就是不显示保存对话框