问题写在代码中
public void CreateExcel(DataSet ds, string FileName)
{ Microsoft.Office.Interop.Excel.ApplicationClass xlApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Add(true); System.Reflection.Missing miss = System.Reflection.Missing.Value; xlApp.Cells[1, 1] = "编号";
xlApp.Cells[1, 2] = "姓名";
xlApp.Cells[1, 3] = "单位";
xlApp.Cells[1, 4] = "时间";
xlApp.Cells[1, 5] = "内容"; DataTable dt = ds.Tables[0];
int r = 2;
foreach (DataRow dr in dt.Rows)
{
xlApp.Cells[r, 1] = dr["tid"].ToString();
xlApp.Cells[r, 2] = dr["tname"].ToString();
xlApp.Cells[r, 3] = dr["tunit"].ToString();
xlApp.Cells[r, 4] = dr["ttime"].ToString();
xlApp.Cells[r, 5] = dr["tcontent"].ToString();
r++;
} xlApp.get_Range(xlApp.Cells[1, 1], xlApp.Cells[r - 1, 1]).ColumnWidth = 5;
xlApp.get_Range(xlApp.Cells[1, 2], xlApp.Cells[r - 1, 4]).ColumnWidth = 15; xlApp.get_Range(xlApp.Cells[1, 5], xlApp.Cells[r - 1, 5]).ColumnWidth = 80;
//这里宽保持80,但导出的文件的内容是一直横过去的,出了单元格的外面
//怎样才能让他不超出单元格而自动换行呢??? //xlApp.get_Range(xlApp.Cells[1, 5], xlApp.Cells[r - 1, 5]).RowHeight = 50;
xlApp.Visible = false; string filename = DateTime.Now.ToString("yyyyMMddhhmmss"); xlBook.SaveAs(Server.MapPath("~/Upload/execl/" + filename + ".xls"), miss, miss,
miss, miss, miss,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
miss, miss, miss, miss, miss); xlApp.Workbooks.Close();
public void CreateExcel(DataSet ds, string FileName)
{ Microsoft.Office.Interop.Excel.ApplicationClass xlApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Add(true); System.Reflection.Missing miss = System.Reflection.Missing.Value; xlApp.Cells[1, 1] = "编号";
xlApp.Cells[1, 2] = "姓名";
xlApp.Cells[1, 3] = "单位";
xlApp.Cells[1, 4] = "时间";
xlApp.Cells[1, 5] = "内容"; DataTable dt = ds.Tables[0];
int r = 2;
foreach (DataRow dr in dt.Rows)
{
xlApp.Cells[r, 1] = dr["tid"].ToString();
xlApp.Cells[r, 2] = dr["tname"].ToString();
xlApp.Cells[r, 3] = dr["tunit"].ToString();
xlApp.Cells[r, 4] = dr["ttime"].ToString();
xlApp.Cells[r, 5] = dr["tcontent"].ToString();
r++;
} xlApp.get_Range(xlApp.Cells[1, 1], xlApp.Cells[r - 1, 1]).ColumnWidth = 5;
xlApp.get_Range(xlApp.Cells[1, 2], xlApp.Cells[r - 1, 4]).ColumnWidth = 15; xlApp.get_Range(xlApp.Cells[1, 5], xlApp.Cells[r - 1, 5]).ColumnWidth = 80;
//这里宽保持80,但导出的文件的内容是一直横过去的,出了单元格的外面
//怎样才能让他不超出单元格而自动换行呢??? //xlApp.get_Range(xlApp.Cells[1, 5], xlApp.Cells[r - 1, 5]).RowHeight = 50;
xlApp.Visible = false; string filename = DateTime.Now.ToString("yyyyMMddhhmmss"); xlBook.SaveAs(Server.MapPath("~/Upload/execl/" + filename + ".xls"), miss, miss,
miss, miss, miss,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
miss, miss, miss, miss, miss); xlApp.Workbooks.Close();
解决方案 »
- 一个sql语句
- session共享SQLServer模式为何取不到session急...
- 伪静态发布IIS后 无法浏览 在线等
- 求MySql.Data, Version=5.2.5.0这个版本的dll文件 (急,急,急)[
- 如何关闭 VSS2008 自动CSS样式?
- 论坛的踢人,让所踢出去的人退出
- 一页只能有一个服务器端 Form 标记,不是一般问题!
- 有关DataFormatString的问题﹗﹗
- 关于datalist中分页的一种新尝试,希望大家帮忙一起看一看,谢谢了。高手请进!
- 一个超简单的问题~~response.write的问题~~~
- 新开发的Jquery UI Widget,大家可以看看
- 简单的问题
或者在文本中的合适位置插入几个\n强制换行
看来你是用了.net 4的dynamic特性