下面的代码我在自己的电脑上运行没有问题,但是发布到服务器上,excel的运行,和传真的运行都没有反应,也没有报错误。 DateTime beforeTime;
DateTime afterTime;
beforeTime = DateTime.Now; //创建Application对象
Excel.Application xApp = new Excel.ApplicationClass();
xApp.Visible = true;
afterTime = DateTime.Now;
// 获取当前行索引
int index = Convert.ToInt32(e.CommandArgument); // 取出当前行数据键值对象中的值
string strGrup = ((GridView)sender).DataKeys[index].Values["in_no"].ToString();
in_warehouse iw = new in_warehouse();
iw.Where.Id.Value = strGrup;
iw.Where.Id.Operator = WhereParameter.Operand.Equal;
iw.Query.Load();
out_warehouse ow = new out_warehouse();
ow.Where.In_no.Value = iw.Id.ToString();
ow.Where.In_no.Operator = WhereParameter.Operand.Equal;
ow.Query.Load();
Mcustomer mc = new Mcustomer();
mc.Where.Id.Value = Convert.ToInt32(ow.Customer_no);
mc.Where.Id.Operator = WhereParameter.Operand.Equal;
mc.Query.Load(); //得到workbook对象,(打开已有的文件)
Excel.Workbook xBook = xApp.Workbooks._Open(@Server.MapPath("../word/zbs/" + iw.Zbs_map), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
//指定要操作的sheet
Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
//写入数据
Excel.Range rng3 = xSheet.get_Range("A1", Missing.Value);
rng3.Value2 = "青海桥头铝电有限公司 " + mc.Title.Substring(2, 1);
xBook.Save();
//xSheet = null;
//xBook = null;
//xApp.Quit();
//xApp = null;
xBook.Close(null, null, null);
xApp.Workbooks.Close();
xApp.Quit();
if (rng3 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng3);
rng3 = null;
}
if (xSheet != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSheet);
xSheet = null;
}
if (xBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBook);
xBook = null;
}
if (xApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xApp);
xApp = null;
}
GC.Collect();
this.KillExcelProcess(beforeTime, afterTime);
faxobject fb = new faxobject();
fb.SendFax(Server.MapPath("../word/zbs/"), Server.MapPath("../word/zbs/" + iw.Zbs_map), mc.Title.Substring(1, mc.Title.Length - 1), "9," + mc.Fax_no);
Response.Redirect("zbs_list.aspx");
DateTime afterTime;
beforeTime = DateTime.Now; //创建Application对象
Excel.Application xApp = new Excel.ApplicationClass();
xApp.Visible = true;
afterTime = DateTime.Now;
// 获取当前行索引
int index = Convert.ToInt32(e.CommandArgument); // 取出当前行数据键值对象中的值
string strGrup = ((GridView)sender).DataKeys[index].Values["in_no"].ToString();
in_warehouse iw = new in_warehouse();
iw.Where.Id.Value = strGrup;
iw.Where.Id.Operator = WhereParameter.Operand.Equal;
iw.Query.Load();
out_warehouse ow = new out_warehouse();
ow.Where.In_no.Value = iw.Id.ToString();
ow.Where.In_no.Operator = WhereParameter.Operand.Equal;
ow.Query.Load();
Mcustomer mc = new Mcustomer();
mc.Where.Id.Value = Convert.ToInt32(ow.Customer_no);
mc.Where.Id.Operator = WhereParameter.Operand.Equal;
mc.Query.Load(); //得到workbook对象,(打开已有的文件)
Excel.Workbook xBook = xApp.Workbooks._Open(@Server.MapPath("../word/zbs/" + iw.Zbs_map), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
//指定要操作的sheet
Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
//写入数据
Excel.Range rng3 = xSheet.get_Range("A1", Missing.Value);
rng3.Value2 = "青海桥头铝电有限公司 " + mc.Title.Substring(2, 1);
xBook.Save();
//xSheet = null;
//xBook = null;
//xApp.Quit();
//xApp = null;
xBook.Close(null, null, null);
xApp.Workbooks.Close();
xApp.Quit();
if (rng3 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(rng3);
rng3 = null;
}
if (xSheet != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSheet);
xSheet = null;
}
if (xBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBook);
xBook = null;
}
if (xApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xApp);
xApp = null;
}
GC.Collect();
this.KillExcelProcess(beforeTime, afterTime);
faxobject fb = new faxobject();
fb.SendFax(Server.MapPath("../word/zbs/"), Server.MapPath("../word/zbs/" + iw.Zbs_map), mc.Title.Substring(1, mc.Title.Length - 1), "9," + mc.Fax_no);
Response.Redirect("zbs_list.aspx");
解决方案 »
- 高手呢 高手在哪里 解决问题 50分就是你的了
- DSOFramer控件上传DOCX文档到服务器后,打不开。错误说文档已经损坏
- 如何确定treeview的那个节点被选中,并引发一定的事件。。
- asp.net 1.1中能不能实现点击关闭网页页面?
- 求正解 要完整过程
- 关于连接数据库很初级的问题请教!!!
- 关于Web Service的问题,大家棒棒忙
- c# winform 打开图片文件
- datatable 动态列 分组
- 请问如何通过点击一个按钮,然后弹出
- datagridview可不可以嵌套的呀 ??? 还有怎么把checkbox或textbox放到单元格里呀???
- MSDN中下载的typeof程序运行结果有疑问
重装服务器的excel试一下
2,本地是ADMINISTRATOR帐户运行,服务器是GUESTS帐户运行