日期:2014-05-17 浏览次数:20564 次
求高手帮忙解决问题 在vs中打开可以直接导出到excel。但是部署到IIS中无法导出。 我在DCOM配置里已经配置好了权限,就是交互式用户,添加用户权限等配置。 但是还是无法导出。 还有什么别的办法?[/quote/// <summary> /// 主要打印功能 /// </summary> /// <param name="fileName"></param> /// <param name="strExcelToTable">网页中的html代码</param> public static void ToExcel(string fileName, string strExcelToTable) { DateTime dt = DateTime.Now; string name = fileName + dt.Year.ToString() + dt.Month.ToString()+dt.Day.ToString()+dt.Hour.ToString()+dt.Minute.ToString()+dt.Second.ToString(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(name) + ".xls"); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/excel"; HttpContext.Current.Response.Write(""); HttpContext.Current.Response.Write(strExcelToTable.ToString()); HttpContext.Current.Response.Write(""); HttpContext.Current.Response.End(); } 这是我自己写的strExcelToTable是自己拼出的table------解决方案--------------------不过要添加Microsoft.Office.Interop.Excel的引用------解决方案--------------------用Microsoft.Office.Interop.Excel类库------解决方案------
/// <summary> /// 主要打印功能 /// </summary> /// <param name="fileName"></param> /// <param name="strExcelToTable">网页中的html代码</param> public static void ToExcel(string fileName, string strExcelToTable) { DateTime dt = DateTime.Now; string name = fileName + dt.Year.ToString() + dt.Month.ToString()+dt.Day.ToString()+dt.Hour.ToString()+dt.Minute.ToString()+dt.Second.ToString(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(name) + ".xls"); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/excel"; HttpContext.Current.Response.Write(""); HttpContext.Current.Response.Write(strExcelToTable.ToString()); HttpContext.Current.Response.Write(""); HttpContext.Current.Response.End(); }