ssl Excel 问题
//打开Excel
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Application.DisplayAlerts = false;
//可见
app.Visible = false;
//模板存在
if (mode.Exists) {
Microsoft.Office.Interop.Excel.Workbook tworkbook;
Object missing = System.Reflection.Missing.Value;
app.Workbooks.Add(missing);
//新建工作簿
tworkbook = app.Workbooks.Open(mode.FullName, missing,
missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing);
//新建工作页
Microsoft.Office.Interop.Excel.Worksheet tworksheet = (Microsoft.Office.Interop.Excel.Worksheet)tworkbook.Sheets[1];
if (_printType == "CusCheck") {
//对模板赋值
setWorkSheet1(dt, tworksheet);)
//保存工作页
tworksheet.SaveAs(newpath, missing, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missing, missing, missing);
//关闭工作簿
tworkbook.Close(false, mode.FullName, missing);
app.Workbooks.Close();
app.Quit();
if (app != null) {
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("Excel")) {
//先判断当前进程是否是excel
if (!p.CloseMainWindow()) {
try {
p.Kill();
} catch (Exception ex) {
LoggingManager.Fatal(ex.ToString());
}
}
}
}
tworkbook = null;
app = null;
GC.Collect();
}
//打开保存对话框
respon.Clear();
respon.ClearHeaders();
respon.Buffer = false;
respon.Charset = "UTF-8";
respon.ContentType = "application/ms-excel";
respon.AddHeader("Content-Disposition", "attachment;filename=" + server.UrlEncode(mode.Name));
respon.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
respon.AddHeader("Content-Length", mode.Length.ToString());
respon.WriteFile(newpath);
//删除创建的Excel文件
FileInfo fileinf = new FileInfo(newpath);
fileinf.Delete();
//关闭连接
respon.Flush();
respon.End();