/// <summary> /// 在线编辑 /// </summary> /// <returns></returns> public ActionResult OfficeEditIndex() { Page page = new Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.SaveFilePage = "/OfficeManager/SaveDoc"; //处理文件保存 pc.ServerPage = "/pageoffice/server.aspx"; //设置授权页面 pc.WebOpen("/UploadFile/MBDoc/firereportmb_sc.doc", PageOffice.OpenModeType.docAdmin, "s-yayn"); page.Controls.Add(pc); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml = controlOutput; return(View()); }
/// <summary> /// 通过pageoffice展示数据 /// 作者:章建国 /// </summary> /// <param name="filename">文件名</param> /// <returns></returns> public ActionResult vpoffice(string filename, string _pname, string _ptype) { if (!string.IsNullOrEmpty(filename)) { ViewBag._pname = _pname; ViewBag._ptype = _ptype; ViewBag.Message = "Your contact page."; Page page = new Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.SaveFilePage = "/Documents/SaveDoc?filename=" + filename; pc.ServerPage = "/pageoffice/server.aspx"; var openmodeltype = PageOffice.OpenModeType.docAdmin; try { var filenames = filename.Split('.'); switch (filenames[1]) { case "doc": openmodeltype = PageOffice.OpenModeType.docNormalEdit; break; case "docx": openmodeltype = PageOffice.OpenModeType.docNormalEdit; break; case "xlsx": openmodeltype = PageOffice.OpenModeType.xlsNormalEdit; break; case "xls": openmodeltype = PageOffice.OpenModeType.xlsNormalEdit; break; case "pptx": openmodeltype = PageOffice.OpenModeType.pptNormalEdit; break; case "ppt": openmodeltype = PageOffice.OpenModeType.pptNormalEdit; break; } } catch { } pc.WebOpen("/UpFile/" + filename, openmodeltype, "s"); page.Controls.Add(pc); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml = controlOutput; } return(View()); }
public ActionResult Show(string id) { //定义Workbook对象 PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook(); System.Web.UI.Page page = new System.Web.UI.Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.ID = "PageOfficeCtrl1"; pc.ServerPage = "/pageoffice/server.aspx"; pc.AddCustomToolButton("保存", "Save()", 1); string filePath = Server.MapPath(id.Replace("..", "~")); pc.SaveFilePage = "/PREPARE_SCHEME/SaveFile/?id=" + id.Replace("..", "~"); pc.Caption = "------------------------------------^o^------------------双击我,最大化------------------^o^------------------------------------"; pc.SetWriter(workBook); pc.WebOpen(filePath, PageOffice.OpenModeType.xlsNormalEdit, "Tom"); page.Controls.Add(pc); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml22 = controlOutput; return(View()); }
public ActionResult BaoGao(string id) { //定义Workbook对象 PageOffice.ExcelWriter.Workbook workBook = new PageOffice.ExcelWriter.Workbook(); System.Web.UI.Page page = new System.Web.UI.Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.ID = "PageOfficeCtrl1"; pc.ServerPage = "/pageoffice/server.aspx"; string filePath = Server.MapPath(id.Replace("..", "~")); pc.Caption = "------------------------------------^o^------------------双击我,报告最大化------------------^o^------------------------------------"; pc.SetWriter(workBook); pc.WebOpen(filePath, PageOffice.OpenModeType.xlsReadOnly, "13718511828"); page.Controls.Add(pc); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml22 = controlOutput; return(View()); }
public ActionResult Word() { ViewBag.Message = "Your contact page."; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.AddCustomToolButton("保存", "Save()", 1); pc.SaveFilePage = "/Word/SaveDoc"; pc.ServerPage = "/pageoffice/server.aspx"; pc.WebOpen("/test.doc", PageOffice.OpenModeType.docAdmin, "s"); ViewBag.EditorHtml = pc.GetHtmlCode("PageOfficeCtrl1"); return(View()); }
public void GetWordSelfReprot(string filename) { filename = HttpUtility.UrlDecode(filename); PageOffice.PageOfficeCtrl PageOfficeCtrl1 = new PageOffice.PageOfficeCtrl(); PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; PageOfficeCtrl1.SaveFilePage = Request.ApplicationPath + "/AssessmentManage/AssessmentSum/SaveFile?filename=" + HttpUtility.UrlEncode(filename); PageOfficeCtrl1.Titlebar = true; //隐藏标题栏 PageOfficeCtrl1.Menubar = true; //隐藏菜单栏 PageOfficeCtrl1.CustomToolbar = true; //隐藏自定义工具栏 PageOfficeCtrl1.OfficeToolbars = true; //隐藏Office工具栏 PageOfficeCtrl1.Theme = PageOffice.ThemeType.CustomStyle; string filePath = Server.MapPath(string.Format("~/Resource/ExcelTemplate/SelfReport/{0}", filename)); PageOfficeCtrl1.WebOpen(filePath, PageOffice.OpenModeType.docNormalEdit, "lm"); Response.Write(PageOfficeCtrl1.GetHtmlCode("PageOfficeCtrl1")); Response.End(); }
public ActionResult Doc(int id, bool edit = false) { var file = Core.FileManager.GetModel(id); if (file == null) { throw new Exception("文件未找到"); } //如果是word文档,则需要转为pdf 并替换原来的word文件 if (!file.IsWordFile) { throw new Exception("该文件不是Word文件"); } var page = new Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl { SaveFilePage = Url.Action("Savedoc", new { id }), ServerPage = "/pageoffice/server.aspx", Menubar = false, CustomToolbar = false, Caption = file.FileName, }; pc.WebOpen(file.PhysicalPath, edit ? PageOffice.OpenModeType.docNormalEdit : PageOffice.OpenModeType.docReadOnly, Identity != null ? Identity.Name : "未知"); page.Controls.Add(pc); var sb = new StringBuilder(); using (var sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml = controlOutput; return(View()); }
protected void Page_Load(object sender, EventArgs e) { Response.Write("param1:" + Request["param1"]); Response.Write("<br>"); Response.Write("param2:" + Request["param2"]); PageOffice.PageOfficeCtrl PageOfficeCtrl1 = new PageOffice.PageOfficeCtrl(); // 设置PageOffice组件服务页面 /** * 如果访问项目的时候浏览器地址栏中的地址都不带后缀(例如"http://localhost:3306/Samples/Deafult"),则这里给ServerPage赋值的时候也不能带后缀, * 直接就是“ PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server";”,否则会报“error:0”的错误 */ PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; // 设置保存文件页面 PageOfficeCtrl1.SaveFilePage = "SaveFile.aspx"; // 打开文档 PageOfficeCtrl1.WebOpen("doc/test.doc", PageOffice.OpenModeType.docNormalEdit, "Tom"); Response.Write(PageOfficeCtrl1.GetHtmlCode("PageOfficeCtrl1")); Response.End(); }
public void GetWord(string fileUrl) { fileUrl = HttpUtility.UrlDecode(fileUrl); // 打开文档 //string filePath = Server.MapPath(Request.ApplicationPath + "/Resource/EmergencyPlan/" + fileUrl); //用于去掉前面的~号 //fileUrl = fileUrl.Substring(1); string filePath = Server.MapPath(fileUrl); //string filePath = Request.ApplicationPath + "/Resource/EmergencyPlan/" + fileUrl; string[] files = filePath.Split('.'); if (files[files.Length - 1] == "pdf") { PageOffice.PDFCtrl PdfCtrl1 = new PageOffice.PDFCtrl(); PdfCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; PdfCtrl1.AddCustomToolButton("打印", "Print()", 6); //PdfCtrl1.AddCustomToolButton("-", "", 0); //PdfCtrl1.AddCustomToolButton("显示/隐藏书签", "SwitchBKMK()", 0); //PdfCtrl1.AddCustomToolButton("实际大小", "SetPageReal()", 16); //PdfCtrl1.AddCustomToolButton("适合页面", "SetPageFit()", 17); //PdfCtrl1.AddCustomToolButton("适合宽度", "SetPageWidth()", 18); //PdfCtrl1.AddCustomToolButton("-", "", 0); //PdfCtrl1.AddCustomToolButton("首页", "FirstPage()", 0); //PdfCtrl1.AddCustomToolButton("上一页", "PreviousPage()", 9); //PdfCtrl1.AddCustomToolButton("下一页", "NextPage()", 10); //PdfCtrl1.AddCustomToolButton("尾页", "LastPage()", 11); //PdfCtrl1.AddCustomToolButton("-", "", 0); PdfCtrl1.WebOpen(filePath); Response.Write(PdfCtrl1.GetHtmlCode("PdfCtrl1")); Response.End(); } else if (files[files.Length - 1] == "xls" || files[files.Length - 1] == "xlsx" || files[files.Length - 1] == "doc" || files[files.Length - 1] == "docx" || files[files.Length - 1] == "ppt" || files[files.Length - 1] == "pptx") { PageOffice.PageOfficeCtrl PageOfficeCtrl1 = new PageOffice.PageOfficeCtrl(); PageOfficeCtrl1.ServerPage = Request.ApplicationPath + "/pageoffice/server.aspx"; // 设置保存文件页面 //PageOfficeCtrl1.SaveFilePage = Server.MapPath(Request.ApplicationPath + "/DayCheckManage/EmergencyPlan/SaveFile?filrUrl=EmergencyPlan&keyValue=" + keyValue); //PageOfficeCtrl1.SaveFilePage = Request.ApplicationPath + "/DayCheckManage/EmergencyPlan/SaveFile?filrUrl=EmergencyPlan&keyValue=" + keyValue; //添加自定义按钮 //PageOfficeCtrl1.Caption = "文档编辑"; PageOfficeCtrl1.Titlebar = false; //隐藏标题栏 PageOfficeCtrl1.Menubar = false; //隐藏菜单栏 PageOfficeCtrl1.CustomToolbar = false; //隐藏自定义工具栏 PageOfficeCtrl1.OfficeToolbars = false; //隐藏Office工具栏 PageOfficeCtrl1.Theme = PageOffice.ThemeType.CustomStyle; if (files[files.Length - 1] == "doc" || files[files.Length - 1] == "docx") //判断是否是word { PageOfficeCtrl1.WebOpen(filePath, PageOffice.OpenModeType.docReadOnly, "fwz"); } else if (files[files.Length - 1] == "xls" || files[files.Length - 1] == "xlsx") { PageOfficeCtrl1.WebOpen(filePath, PageOffice.OpenModeType.xlsReadOnly, "fwz"); } else if (files[files.Length - 1] == "ppt" || files[files.Length - 1] == "pptx") { PageOfficeCtrl1.WebOpen(filePath, PageOffice.OpenModeType.pptReadOnly, "fwz");//没有的类型用word打开 } else { PageOfficeCtrl1.WebOpen(filePath, PageOffice.OpenModeType.docReadOnly, "fwz");//没有的类型用word打开 } Response.Write(PageOfficeCtrl1.GetHtmlCode("PageOfficeCtrl1")); Response.End(); } }
/// <summary> /// 文件预览 /// </summary> /// <returns></returns> public ActionResult FileView(string filename, string SaveFilePage, string SaveDataPage, string DataRange) { if (!string.IsNullOrEmpty(filename)) { while (SaveFilePage.IndexOf('|') > -1) { SaveFilePage = SaveFilePage.Replace('|', '&'); } while (SaveDataPage.IndexOf('|') > -1) { SaveDataPage = SaveDataPage.Replace('|', '&'); } Page page = new Page(); string controlOutput = string.Empty; PageOffice.PageOfficeCtrl pc = new PageOffice.PageOfficeCtrl(); pc.SaveFilePage = SaveFilePage; pc.ServerPage = "/pageoffice/server.aspx"; if (!string.IsNullOrEmpty(SaveDataPage) && !string.IsNullOrEmpty(DataRange)) { PageOffice.ExcelWriter.Workbook wb = new PageOffice.ExcelWriter.Workbook(); PageOffice.ExcelWriter.Sheet sheetOrder = wb.OpenSheet("Sheet1"); PageOffice.ExcelWriter.Table table = sheetOrder.OpenTable(DataRange); pc.SetWriter(wb); pc.SaveDataPage = SaveDataPage; } var openmodeltype = PageOffice.OpenModeType.docAdmin; try { var filenames = filename.Split('.'); switch (filenames[1]) { case "doc": openmodeltype = PageOffice.OpenModeType.docNormalEdit; break; case "docx": openmodeltype = PageOffice.OpenModeType.docNormalEdit; break; case "xlsx": openmodeltype = PageOffice.OpenModeType.xlsNormalEdit; break; case "xls": openmodeltype = PageOffice.OpenModeType.xlsNormalEdit; break; case "pptx": openmodeltype = PageOffice.OpenModeType.pptNormalEdit; break; case "ppt": openmodeltype = PageOffice.OpenModeType.pptNormalEdit; break; } } catch { } pc.WebOpen("/UpFile/" + filename, openmodeltype, "s"); page.Controls.Add(pc); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter htw = new HtmlTextWriter(sw)) { Server.Execute(page, htw, false); controlOutput = sb.ToString(); } } ViewBag.EditorHtml = controlOutput; } return(View()); }