/// <summary> /// 将Word文档转化为HTML /// </summary> /// <param name="WordFileDir"></param> /// <returns></returns> public static string CreateWordToHtmlTemp(string WordFileDir) { string Extension = System.IO.Path.GetExtension(WordFileDir).ToLower(); string FileName = System.IO.Path.GetFileNameWithoutExtension(WordFileDir); //string FilePath = CConfig.GetValueByKey("Officalfolder"); ; string FilePath = CConfig.GetValueByKey("HTMLfolder");; string HtmlPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + FilePath; if (Extension == ".doc" || Extension == ".docx") { try { Aspose.Words.Document doc = new Aspose.Words.Document(WordFileDir); //转换成html doc.Save(HtmlPath + "\\" + FileName + ".html", Aspose.Words.SaveFormat.Html); string strTemp = File.ReadAllText(HtmlPath + "\\" + FileName + ".html").Replace("img src=\"", "img src=\"../" + FilePath + "/"); strTemp = strTemp.Replace("?", " "); //File.Delete(FileName + Extension); File.Delete(HtmlPath + "\\" + FileName + ".html"); File.Delete(WordFileDir); return(strTemp); } catch (Exception e) { string msg = e.Message; return(""); } } else { return(""); } }
public static void ChangDataSourse(string type) { if (type == "KSTDD") { ConnString = CConfig.GetValueByKey("OracleConnStringMark"); } else { ConnString = CConfig.GetValueByKey("OracleConnString"); } }
// <summary> /// 将Word文档转化为HTML(公文) /// </summary> /// <param name="WordFileDir"></param> /// <returns></returns> public static string CreateWordToHtmlTelFile(string WordFileDir) { string Extension = System.IO.Path.GetExtension(WordFileDir).ToLower(); string FileName = System.IO.Path.GetFileNameWithoutExtension(WordFileDir); string FilePath = CConfig.GetValueByKey("HTMLfolder");; string HtmlPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + FilePath; if (Extension == ".doc" || Extension == ".docx") { try { Aspose.Words.Document doc = new Aspose.Words.Document(WordFileDir); //转换成html doc.Save(HtmlPath + "\\" + FileName + ".html", Aspose.Words.SaveFormat.Html); string strTemp = File.ReadAllText(HtmlPath + "\\" + FileName + ".html").Replace("img src=\"", "img src=\"../" + FilePath + "/"); strTemp = strTemp.Replace("?", " "); //doc.SaveToPdf(HtmlPath + "\\" + FileName + ".pdf"); //if (Extension == ".doc") //{ // doc.Save(HtmlPath + "\\ToPdf\\" + FileName + Extension, Aspose.Words.SaveFormat.Doc); //} //else //{ // doc.Save(HtmlPath + "\\ToPdf\\" + FileName + Extension, Aspose.Words.SaveFormat.Docx); //} //doc.Save(HtmlPath + "\\" + FileName + ".pdf", Aspose.Words.SaveFormat.Pdf); //转换成图片 //doc.SaveToImage(0, doc.PageCount, CFetch.MapPath(FileName + ".tiff"), new Aspose.Words.Rendering.ImageOptions()); //this.TB_Content.Text = "<img src=" + CAppSettings.SitePath + FileName + ".tiff" + " />"; //File.Delete(FileName + Extension); File.Delete(HtmlPath + "\\" + FileName + ".html"); return(strTemp); } catch (Exception e) { string msg = e.Message; return(""); } } else { return(""); } }
/// @从视频文件截图,生成在视频文件所在文件夹 /// 在Web.Config 中需要两个前置配置项: /// 1.ffmpeg.exe文件的路径 /// /// 2.截图的尺寸大小 /// /// 3.视频处理程序ffmpeg.exe /// /// 视频文件地址,如:/Web/FlvFile/User1/00001.Flv /// 成功:返回图片虚拟地址; 失败:返回空字符串 public string CatchImg(string vFileName, string imgPath) { //取得ffmpeg.exe的路径,路径配置在Web.Config中,如: string ffmpeg = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "bin/ffmpeg.exe"; //CConfig.GetValueByKey("ffmpeg"); if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(vFileName))) { return(""); } //获得图片相对路径/最后存储到数据库的路径,如:/Web/FlvFile/User1/00001.jpg string flv_img = System.IO.Path.ChangeExtension(vFileName, ".jpg"); //图片绝对路径,如:D:\Video\Web\FlvFile\User1\0001.jpg string imgName = CFun.Create12ID() + CFile.GetFileName(flv_img); string flv_img_p = imgPath + "/" + imgName; //截图的尺寸大小,配置在Web.Config中,如: string FlvImgSize = CConfig.GetValueByKey("CatchFlvImgSize"); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //此处组合成ffmpeg.exe文件需要的参数即可,此处命令在ffmpeg 0.4.9调试通过 startInfo.Arguments = " -i " + vFileName + " -y -f image2 -t 0.001 -s " + FlvImgSize + " " + flv_img_p; try { System.Diagnostics.Process.Start(startInfo); } catch { return(""); } ///注意:图片截取成功后,数据由内存缓存写到磁盘需要时间较长,大概在3,4秒甚至更长; ///这儿需要延时后再检测,我服务器延时8秒,即如果超过8秒图片仍不存在,认为截图失败; ///此处略去延时代码.如有那位知道如何捕捉ffmpeg.exe截图失败消息,请告知,先谢过! while (System.IO.File.Exists(flv_img_p) == false) { Thread.Sleep(2000); } return(imgName); //if (System.IO.File.Exists(flv_img_p)) //{ // return imgName; //} // return ""; }
/// <summary> /// 将Word文档转化为HTML /// </summary> /// <param name="WordFileDir"></param> /// <returns></returns> public static string CreateWordToHtml(string WordFileDir) { string Extension = System.IO.Path.GetExtension(WordFileDir).ToLower(); string FileName = System.IO.Path.GetFileNameWithoutExtension(WordFileDir); //string FilePath = CConfig.GetValueByKey("Officalfolder"); ; string FilePath = CConfig.GetValueByKey("HTMLfolder");; string HtmlPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + FilePath; if (Extension == ".doc" || Extension == ".docx") { try { Aspose.Words.Document doc = new Aspose.Words.Document(WordFileDir); //转换成html doc.Save(HtmlPath + "\\" + FileName + ".html", Aspose.Words.SaveFormat.Html); string strTemp = File.ReadAllText(HtmlPath + "\\" + FileName + ".html").Replace("img src=\"", "img src=\"../" + FilePath + "/"); strTemp = strTemp.Replace("?", " "); //doc.SaveToPdf(HtmlPath + "\\" + FileName + ".pdf"); //if (Extension == ".doc") //{ // doc.Save(HtmlPath + "\\ToPdf\\" + FileName + Extension, Aspose.Words.SaveFormat.Doc); //} //else //{ // doc.Save(HtmlPath + "\\ToPdf\\" + FileName + Extension, Aspose.Words.SaveFormat.Docx); //} //doc.Save(HtmlPath + "\\" + FileName + ".pdf", Aspose.Words.SaveFormat.Pdf); //转换成图片 //doc.SaveToImage(0, doc.PageCount, CFetch.MapPath(FileName + ".tiff"), new Aspose.Words.Rendering.ImageOptions()); //this.TB_Content.Text = "<img src=" + CAppSettings.SitePath + FileName + ".tiff" + " />"; //File.Delete(FileName + Extension); File.Delete(HtmlPath + "\\" + FileName + ".html"); return(strTemp); } catch (Exception e) { string msg = e.Message; return(""); } } else { return(""); } //StringBuilder sb = new StringBuilder(); //Microsoft.Office.Interop.Word.ApplicationClass appclass = new Microsoft.Office.Interop.Word.ApplicationClass();//实例化一个Word //Type wordtype = appclass.GetType(); //Microsoft.Office.Interop.Word.Documents docs = appclass.Documents;//获取Document //Type docstype = docs.GetType(); //object filename = WordFileDir;//Word文件的路径 //Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docstype.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new object[] { filename, true, true });//打开文件 //Type doctype = doc.GetType(); ////object savefilename = @"C:\bb.html";//生成HTML的路径和名子 //object savefilename = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + @"htmltemp\templ" + CreateID() + ".html"; //doctype.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });//另存为Html格式 //wordtype.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, appclass, null);//退出 ////Thread.Sleep(3000);//为了使退出完全,这里阻塞3秒 //StreamReader objreader =null; //bool isChange = true; //int i = 0; //do //{ // System.Threading.Thread.Sleep(3000); // try // { // objreader = new StreamReader(savefilename.ToString(), System.Text.Encoding.GetEncoding("GB2312")); //以下内容是为了在Html中加入对本身Word文件的下载 // isChange = false; // } // catch // { // isChange = true; // } // i++; // if (i > 10) // { // isChange = false; // } //} //while (isChange); //FileStream fs = new FileStream(savefilename.ToString().Split('.').GetValue(0).ToString() + "$.html", FileMode.Create); //StreamWriter streamHtmlHelp = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312")); //string str = ""; //do //{ // str = objreader.ReadLine(); // sb.Append(str + "\n"); // //sb.Replace("<Html>", ""); // //sb.Replace("<body>", ""); // streamHtmlHelp.WriteLine(str); //} //while (str != "</html>"); //streamHtmlHelp.Close(); //objreader.Close(); ////System.Threading.Thread.Sleep(10000); //File.Delete(savefilename.ToString()); //File.Delete(savefilename.ToString().Split('.').GetValue(0).ToString() + "$.html"); ////File.Move(savefilename.ToString().Split('.').GetValue(0).ToString() + "$.html", savefilename.ToString()); //string strTemp = Regex.Match(sb.ToString(), @"<body[\s\S]*?</body>", RegexOptions.IgnoreCase).Value; //string body = Regex.Match(sb.ToString(), @"<body[\s\S]*?'>", RegexOptions.IgnoreCase).Value; //strTemp = Regex.Replace(strTemp, body, "", RegexOptions.IgnoreCase | RegexOptions.Singleline); //strTemp = Regex.Replace(strTemp, "</body>","", RegexOptions.IgnoreCase | RegexOptions.Singleline); //return strTemp;// sb.ToString(); }