导出Excel 并且适应列宽的长度
来源:互联网 发布:中国象棋对弈软件 编辑:程序博客网 时间:2024/05/16 12:22
///DataObject[] 可以把它试做为DataTable
private void ExportExcel(DataObject[] objs)
{
//读取Excel路徑
string excelSource = Server.MapPath("SIP016Export.xls");
string FileName = "SIP016Export.xls";
string tempFolder = "../../../tempFolder/";
string tempFilePath = Server.MapPath(tempFolder + FileName);
File.Copy(excelSource, tempFilePath, true);
object missing = System.Type.Missing;
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Workbook workbook = app.Workbooks._Open(tempFilePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Worksheet worksheet = (Worksheet)workbook.Worksheets[1];
app.Visible = false;
for (int i = 0; i < objs.Length; i++)
{
worksheet.Cells[i + 2, 1] = objs[i].getData("SUNITATRR_CV");
worksheet.Cells[i + 2, 2] = objs[i].getData("SORG_CV");
worksheet.Cells[i + 2, 3] = objs[i].getData("SSUBJECT_CV");
worksheet.Cells[i + 2, 4] = objs[i].getData("SMSUBJECT_CV");
}
worksheet.Columns.EntireColumn.AutoFit();//列宽自适应
workbook.Save();
app.Quit();
string path = GetRootURI() + "/tempFolder/SIP016Export.xls?date=" + DateTime.Now.ToString();
Response.Write("window.open('" + path + "','download','height=50,width=50,top=0,left=0');");
}
/// <summary>
/// 獲取平臺web物理路徑
/// </summary>
/// <returns></returns>
public string GetRootURI()
{
string AppPath = "";
HttpContext HttpCurrent = HttpContext.Current;
HttpRequest Req;
if (HttpCurrent != null)
{
Req = HttpCurrent.Request;
string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
{
AppPath = UrlAuthority;
}
else
{
AppPath = UrlAuthority + Req.ApplicationPath;
}
}
return AppPath;
}
- 导出Excel 并且适应列宽的长度
- jsaper导出的excel自动适应长度
- POI 导出Excel 并且根据内容设置列宽自适应
- 导出Excel -----选择想要导出的列
- PHP导出Excel文件时导出列的数字长度太长时显示不完整或者乱码显示
- npoi导出的excel中设置列宽
- C#导出带有格式的Excel(列宽,合…
- 适应列宽
- 适应列宽
- ext 另类导出excel 只导出显示的列
- 后台导出GridView到Excel,可选择要导出的列
- 导出到Excel并且取消默认的科学计算法
- 导出excel,并且解决身份证科学计数发的问题
- NPOI导出Excel - 自动适应中文宽度
- DBGridEh自动适应列宽
- OneThink+PHPExcel灵活适应导出数据Excel表(导出)
- DBGridEh列宽自动适应内容的简单方法
- asp导出EXCEL数字格式及自动适应宽度的问题
- hibernate.cfg.xml配置注释
- linux 安装qt ./configure error libxcb
- libcurl使用备忘
- objective-C 中两种实现动画的方法(转)
- Sgu 117. Counting
- 导出Excel 并且适应列宽的长度
- CxImage::CreateFromMatrix()
- MD5加密
- 【看日记学Git】之十
- applicationContext.xml 配置文件的存放位置
- Oracle中的Round和Trunc
- 在weblogic下部署jsearch,注册完毕后,要重启weblogic,如果只是单独的重启jsearch应用,大多数时候不管用。
- 我的Android进阶之旅------>Android中使用HTML作布局文件以及调用Javascript
- 各类JAVA代码实现功能