Sample code: Use the Remoting service provided by the SPS to convert the Office document online into an HTML document (including

xiaoxiao2021-03-06  69

Author homepage

Using system; using system.io; using microsoft.htmltrans;

namespace ToHtmlLibrary.Core {///

/// converting the document into an html document Office /// public class TransToHtml {#region Field private string m_SavedHtmlFileName; private string m_SavedPhysicalPath; private string m_ServiceUrl; #endregion # region Property public string SavedHtmlFileName {get {return m_SavedHtmlFileName;} set {m_SavedHtmlFileName = value;}} public string SavedPhysicalPath {get {return m_SavedPhysicalPath;} set {m_SavedPhysicalPath = value;}} public string ServiceUrl {set {m_ServiceUrl = value;} get {RETURN M_SERVICEURL;}} #endregion #Region Construction PUBLIC TRENTML () {} /// ///// /// Convert HTML file storage physical path /// html file name of the file (not including the extension) public TransToHtml (string savePath, string mainFileName) {SavedPhysicalPath = savePath; SavedHtmlFileName = mainFileName } /// ///// /// /// /// url conversion remoting services public TransToHtml (string savePath, string mainFileName, string serviceUrl) {SavedPhysicalPath = savePath; SavedHtmlFileName = mainFileName; ServiceUrl = serviceUrl;} #endregion #region Private Method private string GetVirtualDocumentName (EDocumentType type) { IF (Type.Equals (edocumenttype.word) Return "abc.doc";

IF (type.equals (edocumenttype.excel) Return "abc.xls"; if (Type.Equals (edocumenttype.powerpoint) Return "abc.ppt"; return "";} private void dotrans (byte [] DocuContent, string serviceUrl, EDocumentType type) {if (type.Equals (EDocumentType.Unknow)) {return;} string strTask = Guid.NewGuid () ToString ();. string strDocument = GetVirtualDocumentName (type); // Create Object IHtmlTrLoadBalancer htmlTrLoadBalancer IHtmlTrLoadBalancer = (IHtmlTrLoadBalancer) System.Activator.GetObject (typeof (IHtmlTrLoadBalancer), serviceUrl); // get IHtmlTrLauncher object URI string strLauncherUri = htmlTrLoadBalancer.StrGetLauncher (strTask); // create IHtmlTrLauncher objects IHtmlTrLauncher htmlTrLauncher = (IHtmlTrLauncher) System.Activator. GetObject (typeof (IHtmlTrLauncher), strLauncherUri); // call IHtmlTrLauncher object generation html CreateHtmlInfo chi = htmlTrLauncher.CHICreateHtml (strLauncherUri, docContent, BrowserType.BT_IE4, strDocument, strTask, 90, true); // Object Analyzing IHtmlTrLoadBalancer Whether the task is completed htmlTrLoadBalancer.LauncherTaskCompleted (strLauncherUri, strTask); // check the error output if (chi.ce == CreationErrorType.CE_NONE && chi.fHasMainFile) {Directory.CreateDirectory (SavedPhysicalPath "//" SavedHtmlFileName ); FileStream fs = new FileStream (SavedPhysicalPath "//" SavedHtmlFileName "//" SavedHtmlFileName chi.strMainFileName.Substring (chi.strMainFileName.LastIndexOf () "."), FileMode.Create); BinaryWriter bw = New binarywriter (fs); bw.write (chi.rgbmainfile, 0, chi.rgbmainfile.length); fs.close (); fs = null; bw.close (); bw = null;

转载请注明原文地址:https://www.9cbs.com/read-90752.html

New Post(0)