diff --git a/PROMS/Volian.Utils.Library/MSWord/WordDoc.cs b/PROMS/Volian.Utils.Library/MSWord/WordDoc.cs index 9a5cfe09..e21197ee 100644 --- a/PROMS/Volian.Utils.Library/MSWord/WordDoc.cs +++ b/PROMS/Volian.Utils.Library/MSWord/WordDoc.cs @@ -1,93 +1,44 @@ using System; using System.Collections.Generic; using System.Text; -using System.Reflection; -using Microsoft.Office.Interop; -using Microsoft.Office.Interop.Word; +using LBWordLibrary; namespace Volian.MSWord { public class WordDoc { - private static object optional = Missing.Value; - private static object oFalse = false; - private object oTrue = true; - private object oBlank = ""; - private object oWdStory = WdUnits.wdStory; - private object oWdWord = WdUnits.wdWord; - private object oWdChar = WdUnits.wdCharacter; - private object oWdLine = WdUnits.wdLine; - private object oWdPara = WdUnits.wdParagraph; - private object oWdExtend = WdMovementType.wdExtend; - private object oWdMove = WdMovementType.wdMove; - private object o1 = 1; - private static Application m_App; - // Microsoft.Office.Interop.Word.Application App - // { - // get{return m_App;} - // } - private Document m_Doc; - // Microsoft.Office.Interop.Word.Document Doc - // { - // get{return m_Doc;} - // } - private string mDocName; - + private static LBApplicationClass _MyWordApp; + public static LBApplicationClass MyWordApp + { + get + { + if (_MyWordApp == null) + _MyWordApp = new LBApplicationClass(); + return WordDoc._MyWordApp; + } + } + private LBDocumentClass _MyWordDoc; + public LBDocumentClass MyWordDoc + { + get + { return _MyWordDoc; } + } + private string _DocName; public string DocName { - get { return mDocName; } - set { mDocName = value; } + get { return _DocName; } + set { _DocName = value; } } - public WordDoc(string sPath) + public WordDoc(string docName) { - OpenApp(); - //m_App.Visible = true; - mDocName = sPath; - object oFile = sPath; - m_Doc = m_App.Documents.Open( - ref oFile // FileName - ,ref optional // ConfirmConversions - ,ref optional // ReadOnly - ,ref optional // AddToRecentFiles - ,ref optional // PasswordDocument - ,ref optional // PasswordTemplate - ,ref optional // Revert - ,ref optional // WritePasswordDocument - ,ref optional // WritePasswordTemplate - ,ref optional // Format - ,ref optional // Encoding - ,ref optional // Visible - ,ref optional // OpenAndRepair - ,ref optional // DocumentDirection - ,ref optional // NoEncodingDialog - ,ref optional // XMLTransform - ); + DocName = docName; + _MyWordDoc = MyWordApp.Documents.Open(_DocName, false); } - //~WordDoc() - //{ - // m_App.Quit(ref oFalse, ref optional, ref optional); - //} - private string SaveDoc() + public string Save() { - object oFileName = mDocName; - object oFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument; - //object oFileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML; - object oPassWord = ""; try { - m_Doc.SaveAs2000( - ref oFileName // FileName - ,ref oFileFormat // FileFormat - ,ref oFalse // LockComments - ,ref oPassWord // Password - ,ref oFalse // AddToRecentFiles - ,ref oPassWord // WritePassword - ,ref oFalse // ReadOnlyRecommended - ,ref oFalse // EmbedTrueTypeFonts - ,ref oFalse // SaveNativePictureFormat - ,ref oFalse // SaveFormsData - ,ref oFalse // SaveAsAOCELetter - ); + MyWordDoc.SaveAs(DocName, LBWdSaveFormat.wdFormatDocument); return "Successful Save"; } catch (Exception ex) @@ -95,41 +46,34 @@ namespace Volian.MSWord return string.Format("Error during Doc save - {0}", ex.Message); } } - public string Save() + public string Save(string docName) { - return SaveDoc(); - } - public string Save(string sPath) - { - mDocName = sPath; - return SaveDoc(); + DocName = docName; + return Save(); } public void Close() { - m_Doc.Close(ref oFalse, ref optional, ref optional); - //CloseApp(); + MyWordDoc.Close(false); } public void SetLineSpacing(float linesPerInch) // if need landscape set too: , bool landscape) { - Selection sel = m_App.Selection; - sel.WholeStory(); - // if need landscape set too: if (landscape) sel.PageSetup.Orientation = WdOrientation.wdOrientLandscape; - sel.ParagraphFormat.SpaceBefore=0; - sel.ParagraphFormat.SpaceAfter = 0; - sel.ParagraphFormat.LineSpacingRule = WdLineSpacing.wdLineSpaceExactly; - sel.ParagraphFormat.LineSpacing = 72/linesPerInch; // 12 ==> 6 Lines per inch - } - public void OpenApp() + LBSelection selection = MyWordApp.Selection; + selection.WholeStory(); + selection.ParagraphFormat.SpaceBefore = 0; + selection.ParagraphFormat.SpaceAfter = 0; + selection.ParagraphFormat.LineSpacingRule = LBWdLineSpacing.wdLineSpaceExactly; + selection.ParagraphFormat.LineSpacing = 72 / linesPerInch; + } + public float Length { - if(m_App==null) - m_App = new ApplicationClass(); + get { return MyWordDoc.Length; } } public static void CloseApp() { - if (m_App != null) + if(_MyWordApp != null) { - m_App.Quit(ref oFalse, ref optional, ref optional); - m_App = null; + _MyWordApp.Quit(false); + _MyWordApp=null; } } }