diff --git a/PROMS/LBWordLibrary/LBComObject.cs b/PROMS/LBWordLibrary/LBComObject.cs index ba14534d..0836f078 100644 --- a/PROMS/LBWordLibrary/LBComObject.cs +++ b/PROMS/LBWordLibrary/LBComObject.cs @@ -68,8 +68,17 @@ namespace LBWordLibrary } protected Object InvokeMethod(string methodName, params Object[] parameters) { + if (parameters != null) + FixParameters(parameters); return DoInvokeMember(methodName, parameters, BindingFlags.InvokeMethod, null); } + private void FixParameters(object[] parameters) + { + // Loop through parameters checking to make sure that none of them are LBComObjects + for (int i = 0; i < parameters.Length; i++) + if (parameters[i] is LBComObject) + parameters[i] = (parameters[i] as LBComObject).Item; + } protected Object InvokeMethod(string methodName) { return InvokeMethod(methodName, null); @@ -86,15 +95,15 @@ namespace LBWordLibrary tmp.Item = InvokeMethod("Add"); return tmp; } - public TItem this[int item] - { - get - { - TItem tmp = new TItem(); - tmp.Item = GetProperty("Item", item); - return tmp; - } - } + //public TItem this[int item] + //{ + // get + // { + // TItem tmp = new TItem(); + // tmp.Item = GetProperty("Item", item); + // return tmp; + // } + //} } public partial class LBApplicationClass : LBComObject { @@ -209,6 +218,10 @@ namespace LBWordLibrary { get { return new LBInlineShapes(GetProperty("InlineShapes")); } } + public LBParagraphs Paragraphs + { + get { return new LBParagraphs(GetProperty("Paragraphs")); } + } public void WholeStory() { InvokeMethod("WholeStory"); @@ -241,6 +254,26 @@ namespace LBWordLibrary { return InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; } + public void TypeText(string Text) + { + InvokeMethod("TypeText", Text); + } + public int EndOf() + { + return InvokeMethod("EndOf", Missing.Value, Missing.Value) as int? ?? 0; + } + public int EndOf(object Unit, object Extend) + { + return InvokeMethod("EndOf", Unit, Extend) as int? ?? 0; + } + public LBRange GoTo() + { + return new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + } + public LBRange GoTo(object What, object Which, object Count, object Name) + { + return new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); + } } public partial class LBDocumentClass : LBComObject { @@ -258,6 +291,14 @@ namespace LBWordLibrary { get { return (GetProperty("FullName").ToString()); } } + public LBShapes Shapes + { + get { return new LBShapes(GetProperty("Shapes")); } + } + public LBWindow ActiveWindow + { + get { return new LBWindow(GetProperty("ActiveWindow")); } + } public void SaveAs2000() { InvokeMethod("SaveAs2000", Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); @@ -290,6 +331,14 @@ namespace LBWordLibrary { InvokeMethod("ExportAsFixedFormat", OutputFileName, ExportFormat, OpenAfterExport, OptimizeFor, Range, From, To, Item, IncludeDocProps, KeepIRM, CreateBookmarks, DocStructureTags, BitmapMissingFonts, UseISO19005_1, FixedFormatExtClassPtr); } + public LBRange Range() + { + return new LBRange(InvokeMethod("Range", Missing.Value, Missing.Value)); + } + public LBRange Range(object Start, object End) + { + return new LBRange(InvokeMethod("Range", Start, End)); + } } public partial class LBWindow : LBComObject { @@ -321,6 +370,18 @@ namespace LBWordLibrary { get { return new LBParagraphFormatClass(GetProperty("ParagraphFormat")); } } + public LBParagraphs Paragraphs + { + get { return new LBParagraphs(GetProperty("Paragraphs")); } + } + public LBRange GoTo() + { + return new LBRange(InvokeMethod("GoTo", Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + } + public LBRange GoTo(object What, object Which, object Count, object Name) + { + return new LBRange(InvokeMethod("GoTo", What, Which, Count, Name)); + } } public partial class LBParagraphFormatClass : LBComObject { @@ -444,6 +505,26 @@ namespace LBWordLibrary get { return (LBWdColor)GetProperty("Color"); } set { SetProperty("Color", value); } } + public int Position + { + get { return (GetProperty("Position") as int? ?? 0); } + set { SetProperty("Position", value); } + } + public int Subscript + { + get { return (GetProperty("Subscript") as int? ?? 0); } + set { SetProperty("Subscript", value); } + } + public int Superscript + { + get { return (GetProperty("Superscript") as int? ?? 0); } + set { SetProperty("Superscript", value); } + } + public float Size + { + get { return (GetProperty("Size") as float? ?? 0); } + set { SetProperty("Size", value); } + } } public enum LBWdInformation { @@ -498,6 +579,44 @@ namespace LBWordLibrary return new LBInlineShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Range)); } } + public partial class LBParagraphs : LBComObjectList /* Collection */ + { + public LBParagraphs(Object item) + { + Item = item; + } + public int Count + { + get { return (GetProperty("Count") as int? ?? 0); } + } + public LBParagraph First + { + get { return new LBParagraph(GetProperty("First")); } + } + public LBParagraph Last + { + get { return new LBParagraph(GetProperty("Last")); } + } + public System.Object GetEnumerator() + { + return InvokeMethod("GetEnumerator"); + } + } + public partial class LBShapes : LBComObjectList /* Collection */ + { + public LBShapes(Object item) + { + Item = item; + } + public LBShape AddPicture(string FileName) + { + return new LBShape(InvokeMethod("AddPicture", FileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value)); + } + public LBShape AddPicture(string FileName, object LinkToFile, object SaveWithDocument, object Left, object Top, object Width, object Height, object Anchor) + { + return new LBShape(InvokeMethod("AddPicture", FileName, LinkToFile, SaveWithDocument, Left, Top, Width, Height, Anchor)); + } + } public enum LBWdExportFormat { wdExportFormatPDF = 17, @@ -677,6 +796,39 @@ namespace LBWordLibrary set { SetProperty("Width", value); } } } + public partial class LBParagraph : LBComObject + { + public LBParagraph() { } + public LBParagraph(Object item) : base(item) { } + public LBRange Range + { + get { return new LBRange(GetProperty("Range")); } + } + } + public partial class LBShape : LBComObject + { + public LBShape() { } + public LBShape(Object item) : base(item) { } + public float Height + { + get { return (GetProperty("Height") as float? ?? 0); } + set { SetProperty("Height", value); } + } + public float Width + { + get { return (GetProperty("Width") as float? ?? 0); } + set { SetProperty("Width", value); } + } + public LBRange Anchor + { + get { return new LBRange(GetProperty("Anchor")); } + } + public LBMsoTriState LockAspectRatio + { + get { return (LBMsoTriState)GetProperty("LockAspectRatio"); } + set { SetProperty("LockAspectRatio", value); } + } + } public partial class LBPages : LBComObjectList /* Collection */ { public LBPages(Object item) @@ -847,4 +999,31 @@ namespace LBWordLibrary wdTable = 15, wdItem = 16 } + public enum LBWdGoToDirection + { + wdGoToAbsolute = 1, + wdGoToNext = 2, + wdGoToPrevious = 3, + wdGoToLast = -1 + } + public enum LBWdGoToItem + { + wdGoToSection = 0, + wdGoToPage = 1, + wdGoToTable = 2, + wdGoToLine = 3, + wdGoToFootnote = 4, + wdGoToEndnote = 5, + wdGoToComment = 6, + wdGoToField = 7, + wdGoToGraphic = 8, + wdGoToObject = 9, + wdGoToEquation = 10, + wdGoToHeading = 11, + wdGoToPercent = 12, + wdGoToSpellingError = 13, + wdGoToGrammaticalError = 14, + wdGoToProofreadingError = 15, + wdGoToBookmark = -1 + } } diff --git a/PROMS/LBWordLibrary/LBObjectExtension.cs b/PROMS/LBWordLibrary/LBObjectExtension.cs index d9fe9e11..a03b27c1 100644 --- a/PROMS/LBWordLibrary/LBObjectExtension.cs +++ b/PROMS/LBWordLibrary/LBObjectExtension.cs @@ -19,6 +19,10 @@ namespace LBWordLibrary { InvokeMethod("PrintOut", Background, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } + public void Quit(bool save) + { + InvokeMethod("Quit", save, Missing.Value, Missing.Value); + } public bool VolianPDFInstalled { get @@ -246,6 +250,34 @@ namespace LBWordLibrary { SaveAs2(fileName, format, Missing.Value, Missing.Value, false); } + public LBRange Range(int Start, int End) + { + return new LBRange(InvokeMethod("Range", Start, End)); + } + /// + /// Length is Pages and Partial Pages + /// The integral part is the number of full pages + /// The decimal part is the size of the last page divided by 7200 + /// (the first two digits should be the number of inches) + /// + public float Length + { + get + { + LBPages myPages = ActiveWindow.ActivePane.Pages;// Start with pages + float retval = (float)myPages.Count - 1; + LBRange myRange = Range(); + myRange = myRange.GoTo(LBWdGoToItem.wdGoToPercent, LBWdGoToDirection.wdGoToLast, 100); + float partial = (float) myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage); + partial += myRange.Font.Size; + retval += partial / 7200; + return retval; + } + } + public void Close(bool SaveChanges) + { + InvokeMethod("Close", SaveChanges, Missing.Value, Missing.Value); + } } public partial class LBFind { @@ -264,6 +296,17 @@ namespace LBWordLibrary set { SetProperty("Color", value); } } } + public partial class LBRange : LBComObject + { + public Object get_Information(LBWdInformation info) + { + return GetProperty("Information", info); + } + public LBRange GoTo(LBWdGoToItem What, LBWdGoToDirection Which, int Count) + { + return new LBRange(InvokeMethod("GoTo", What, Which, Count, Missing.Value)); + } + } public partial class LBSelection : LBComObject { public Object get_Information(LBWdInformation info) @@ -282,6 +325,52 @@ namespace LBWordLibrary { return InvokeMethod("EndKey", Unit, Extend) as int? ?? 0; } - } + public partial class LBInlineShapes : LBComObjectList /* Collection */ + { + public LBInlineShape AddPicture(string FileName, LBRange Range) + { + return new LBInlineShape(InvokeMethod("AddPicture", FileName, false, true, Range)); + } + } + public partial class LBShapes : LBComObjectList /* Collection */ + { + public LBShape AddPicture(string FileName, float Left, float Top, LBRange Anchor) + { + return new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Anchor)); + } + public LBShape AddPicture(string FileName, float Left, float Top) + { + return new LBShape(InvokeMethod("AddPicture", FileName, false, true, Left, Top, Missing.Value, Missing.Value, Missing.Value)); + } + } + public enum LBMsoTriState + { + msoCTrue = 1, + msoFalse = 0, + msoTriStateMixed = -2, + msoTriStateToggle = -3, + msoTrue = -1 + } + //public partial class ProcessKiller + //{ + // System.Diagnostics.Process _MyProcess; + // private bool _Exited = false; + // public ProcessKiller(System.Diagnostics.Process myProcess) + // { + // _MyProcess = myProcess; + // _MyProcess.Exited += new EventHandler(_MyProcess_Exited); + // _MyProcess.Kill(); + // DateTime next = DateTime.Now.AddMilliseconds(200); + // while (DateTime.Now < next) + // Application.DoEvents(); + // while (!_Exited) + // Application.DoEvents(); + // } + // void _MyProcess_Exited(object sender, EventArgs e) + // { + // Console.WriteLine("Exited"); + // _Exited = true; + // } + //} }