62,046
社区成员
发帖
与我相关
我的任务
分享
GC.Collect();
ApplicationClass excel;
int rowIndex = 1;
int colIndex = 1;
_Workbook xBk;
_Worksheet xSt;
string sTimes = DateTime.Now.ToString("yyyyMMddHHmmss");
string strFileName = "";
System.IO.FileInfo file;
excel.Cells[rowIndex, colIndex]=“aa” 给excel第一行第一列赋值
#region 保存文件
strFileName = Server.MapPath("Uploads/qafiles/") + "QAIndividualQC" + sTimes + ".xls";
xBk.SaveCopyAs(strFileName);
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
GC.Collect();
file = new System.IO.FileInfo(strFileName);
Response.Clear();
//Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response.AddHeader("Content-Length", file.Length.ToString());
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response.ContentType = "application/ms-excel";
// 把文件流发送到客户端
Response.WriteFile(file.FullName);
Response.Flush();
file.Delete();
// 停止页面的执行
Response.End();
#endregion
set objExcel1=server.CreateObject("Excel.Application")
objExcel1.Workbooks.Open(Server.Mappath("model.xlt")) '用Excel模板定义EXCEL样式
objExcel1.DisplayAlerts=false
objExcel1.Application.Visible=false
objExcel1.Sheets(1).Select '选中工作页
Set sheetActive=objExcel1.ActiveWorkbook.ActiveSheet
sheetActive.range("A1").value=“单元格写入值"