Example #1
0
 /// <summary>
 /// Index the Pivot Tables
 /// </summary>
 /// <param name="name">pivot table name</param>
 /// <returns></returns>
 public PivotTable this[string name]
 {
     get
     {
         return(new PivotTable(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { name })));
     }
 }
 public Workbook this[int id]
 {
     get
     {
         return(new Workbook(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, ComArguments.Prepare(id))));
     }
 }
        /// <summary>
        /// Saves the workbook under a new filename.
        /// </summary>
        /// <param name="filename">The filename under which to save the workbook</param>
        /// <param name="fileFormat">The format in which to save the workbook</param>
        /// <param name="saveAsAccessMode">The file access mode to use when saving</param>
        public void SaveAs(string filename, Enums.FileFormat fileFormat, Enums.SaveAsAccessMode saveAsAccessMode)
        {
            var missing = System.Reflection.Missing.Value;

            InternalObject.GetType().InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { filename, fileFormat, missing, missing,
                                                                                                                                              false, false, saveAsAccessMode });
        }
Example #4
0
 /// <summary>
 /// Retrieves a field from the collection.
 /// This Field must be manually disposed.
 /// </summary>
 /// <param name="idx">Name of the field to retrieve.</param>
 /// <returns>Field</returns>
 public Field this[string idx]
 {
     get
     {
         return(new Field(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { idx })));
     }
 }
Example #5
0
 public CommandBar this[string key]
 {
     get
     {
         return(new CommandBar(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { key })));
     }
 }
 public CommandBarControl this[int index]
 {
     get
     {
         return(WrapCorrectType(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { index })));
     }
 }
Example #7
0
        /// <summary>
        /// Saves a document as PDF or XPS format. (Available from Word 2007)
        /// </summary>
        /// <param name="OutputfileName">The path and file name name of the new PDF or XPS file.</param>
        /// <param name="ExportFormat">Specifies either PDF or XPS format.</param>
        /// <param name="OpenAfterExport">Opens the new file after exporting the contents.</param>
        /// <param name="OptimizeFor">Specifies whether to optimize for screen or print.</param>
        /// <param name="Range">Specifies whether the export range is the entire document, the current page, a range of text, or the current selection. the default is to export the entire document.</param>
        /// <param name="From">Specifies the starting page number, if the Range parameter is set to ExportFromTo.</param>
        /// <param name="To">Specifies the ending page number, if the Range parameter is set to ExportFromTo.</param>
        /// <param name="Item">Specifies whether the export process includes text only or includes text with markup.</param>
        /// <param name="IncludeDocProps">Specifies whether to include document properties in the newly exported file.</param>
        /// <param name="KeepIRM">Specifies whether to copy IRM permissions to an XPS document if the source document has IRM protections. Default value is True.</param>
        /// <param name="CreateBookmarks">Specifies whether to export bookmarks and the type of bookmarks to export.</param>
        /// <param name="DocStructureTags">Specifies whether to include extra data to help screen readers, for example information about the flow and logical organization of the content. Default value is True.</param>
        /// <param name="BitmapMissingFonts">Specifies whether to include a bitmap of the text. Set this parameter to True when font licenses do not permit a font to be embedded in the PDF file. If False, the font is referenced, and the viewer's computer substitutes an appropriate font if the authored one is not available. Default value is True.</param>
        /// <param name="UseISO19005_1">Specifies whether to limit PDF usage to the PDF subset standardized as ISO 19005-1. If True, the resulting files are more reliably self-contained but may be larger or show more visual artifacts due to the restrictions of the format. Default value is False.</param>
        public void ExportAsFixedFormat(string OutputfileName, ExportFormat ExportFormat, bool?OpenAfterExport = false, ExportOptimizeFor?OptimizeFor = ExportOptimizeFor.Print, ExportRange?Range = ExportRange.AllDocument, long?From = null, long?To = null, ExportItem?Item = ExportItem.Content, bool?IncludeDocProps = true, bool?KeepIRM = true, ExportCreateBookmarks?CreateBookmarks = ExportCreateBookmarks.CreateNoBookmarks, bool?DocStructureTags = true, bool?BitmapMissingFonts = true, bool?UseISO19005_1 = false)
        {
            if (String.IsNullOrEmpty(OutputfileName))
            {
                throw new Exception("Output filename may not be blank");
            }

            InternalObject.GetType().InvokeMember("ExportAsFixedFormat", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[]
            {
                OutputfileName,
                ExportFormat,
                OpenAfterExport ?? (object)System.Reflection.Missing.Value,
                OptimizeFor ?? (object)System.Reflection.Missing.Value,
                Range ?? (object)System.Reflection.Missing.Value,
                From ?? (object)System.Reflection.Missing.Value,
                To ?? (object)System.Reflection.Missing.Value,
                Item ?? (object)System.Reflection.Missing.Value,
                IncludeDocProps ?? (object)System.Reflection.Missing.Value,
                KeepIRM ?? (object)System.Reflection.Missing.Value,
                CreateBookmarks ?? (object)System.Reflection.Missing.Value,
                DocStructureTags ?? (object)System.Reflection.Missing.Value,
                BitmapMissingFonts ?? (object)System.Reflection.Missing.Value,
                UseISO19005_1 ?? (object)System.Reflection.Missing.Value,
                (object)System.Reflection.Missing.Value
            });
        }
 /// <summary>
 /// Returns an individual ContentControl object in the collection. The returned ContentControl must be manually disposed.
 /// </summary>
 /// <param name="index">Index of the ContentControl. 1-indexed.</param>
 /// <returns>A ContentControl object.</returns>
 public ContentControl this[long index]
 {
     get
     {
         return(new ContentControl(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { index })));
     }
 }
Example #9
0
            private int Add(object obj, bool threeState, bool _checked, CheckState state, bool setState)
            {
                InternalObject io = new InternalObject
                {
                    Object  = obj,
                    Control = new CheckBox()
                    {
                        ThreeState  = threeState,
                        Text        = (obj != null ? obj.ToString() : string.Empty),
                        Tag         = Guid.NewGuid(),
                        Location    = new Point(0, 0),
                        RightToLeft = parent.RightToLeft,
                        AutoSize    = true,
                        Margin      = new Padding(0)
                    }
                };

                if (setState)
                {
                    io.Control.CheckState = state;
                }
                else
                {
                    io.Control.Checked = _checked;
                }
                io.Control.CheckedChanged    += new EventHandler(Control_CheckedChanged);
                io.Control.CheckStateChanged += new EventHandler(Control_CheckStateChanged);

                items.Add(io);
                parent.UpdateItems();
                return(items.Count - 1);
            }
Example #10
0
 public PivotField this[int id]
 {
     get
     {
         return(new PivotField(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { id })));
     }
 }
Example #11
0
 /// <summary>
 /// Returns an individual Bookmark object in the collection. The returned Bookmark must be manually disposed.
 /// </summary>
 /// <param name="index">Name of the Bookmark.</param>
 /// <returns>A Bookmark object.</returns>
 public Bookmark this[string index]
 {
     get
     {
         return(new Bookmark(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { index })));
     }
 }
Example #12
0
        public void Test()
        {
            TypeFactory.SetGlobalAssembly("InternalTypesTest.dll", new Version(1, 2, 3, 4), "TypeBuilder/InternalTypesTest.snk");

            InternalObject o = TypeAccessor.CreateInstance <InternalObject>();

            Assert.IsNotNull(o);

            PublicObject o2 = TypeAccessor.CreateInstance <PublicObject>();

            Assert.IsNotNull(o2);

            TypeFactory.SaveGlobalAssembly();

            TypeAccessor ta = TypeAccessor <PublicObject> .Instance;

            Assert.IsNotNull(ta["InternalField"]);
            Assert.IsTrue(ta["InternalField"].HasGetter);
            Assert.IsTrue(ta["InternalField"].HasSetter);
            Assert.IsNotNull(ta["PublicValue"]);
            Assert.IsTrue(ta["PublicValue"].HasGetter);
            Assert.IsTrue(ta["PublicValue"].HasSetter);
            Assert.IsNotNull(ta["InternalValue"]);
            Assert.IsTrue(ta["InternalValue"].HasGetter);
            Assert.IsTrue(ta["InternalValue"].HasSetter);
            Assert.IsNotNull(ta["ProtectedInternalValue"]);
            Assert.IsTrue(ta["ProtectedInternalValue"].HasGetter);
            Assert.IsTrue(ta["ProtectedInternalValue"].HasSetter);
            Assert.IsNotNull(ta["NonAbstractValue"]);
            Assert.IsTrue(ta["NonAbstractValue"].HasGetter);
            Assert.IsTrue(ta["NonAbstractValue"].HasSetter);
        }
Example #13
0
        public SortFields Add(Range key, SortOn sortOn = SortOn.Values, SortOrder order = SortOrder.Ascending, SortDataOption dataOption = SortDataOption.Normal)
        {
            InternalObject.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, ComArguments.Prepare(key, sortOn, order, dataOption));

            // I'm returning this since the documentation says it returns 'SortFields' not 'SortField'
            return(this);
        }
Example #14
0
        public object Run(string proc, params object[] args)
        {
            List <object> inArgs = new List <object>(args);

            inArgs.Insert(0, proc);

            return(InternalObject.GetType().InvokeMember("Run", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, inArgs.ToArray()));
        }
Example #15
0
 // TODO: Add some overloads to this.
 /// <summary>
 /// Runs the specified find operation.
 /// </summary>
 /// <param name="replace">Specifies how many replacements are to be made: one, all, or none. Can be any Replace constant.</param>
 /// <returns>True if the find operation is successful.</returns>
 public bool Execute(Replace replace)
 {
     return(Convert.ToBoolean(InternalObject.GetType().InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject,
                                                                    new object[] { replace },
                                                                    null,
                                                                    System.Threading.Thread.CurrentThread.CurrentCulture,
                                                                    new string[] { "Replace" })));
 }
Example #16
0
        /// <summary>
        /// Collapses a range or selection to the starting or ending position. After a range or selection is collapsed, the starting and ending points are equal.
        /// </summary>
        /// <param name="direction">The direction in which to collapse the range or selection.</param>
        public void Collapse(Enums.CollapseDirection?direction = null)
        {
            List <object> args = new List <object>();

            args.Add(direction ?? (object)System.Reflection.Missing.Value);

            InternalObject.GetType().InvokeMember("Collapse", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, args.ToArray());
        }
Example #17
0
        public Picture Insert(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Could not find file " + filename);
            }

            return(new Picture(InternalObject.GetType().InvokeMember("Insert", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { filename })));
        }
Example #18
0
        /// <summary>
        /// Deletes the specified number of characters or words.
        /// </summary>
        /// <param name="unit">The unit by which the collapsed range is to be deleted.</param>
        /// <param name="count">The number of units to be deleted. To delete units after the range, collapse the range and use a positive number. To delete units before the range, collapse the range and use a negative number.</param>
        public void Delete(Enums.Units?unit = null, long?count = null)
        {
            var args = new List <object>();

            args.Add(unit ?? (object)System.Reflection.Missing.Value);
            args.Add(count ?? (object)System.Reflection.Missing.Value);

            InternalObject.GetType().InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, args.ToArray());
        }
Example #19
0
        /// <summary>
        /// Adds a picture to the spreadsheet. The returned shape object must be manually disposed.
        /// </summary>
        /// <param name="filename">Filename of the picture</param>
        /// <param name="linkToFile">Should the spreadsheet retain the file's path?</param>
        /// <param name="saveWithDocument">Should the spreadsheet contain the image data? This must be true if linkToFile is false.</param>
        /// <param name="left">Left position, in points</param>
        /// <param name="top">Top position, in points</param>
        /// <param name="width">Width, in points</param>
        /// <param name="height">Height, in points</param>
        /// <returns></returns>
        public Shape AddPicture(string filename, bool linkToFile, bool saveWithDocument, double left, double top, double width, double height)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("Could not find file " + filename);
            }

            return(new Shape(InternalObject.GetType().InvokeMember("AddPicture", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject,
                                                                   new object[] { filename, linkToFile, saveWithDocument, left, top, width, height })));
        }
        public void Move(Worksheet before = null, Worksheet after = null)
        {
            if (before != null && after != null)
            {
                throw new ArgumentException("You cannot specify both 'before' and 'after' when moving a worksheet");
            }


            InternalObject.GetType().InvokeMember("Move", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { (before == null) ? System.Reflection.Missing.Value : before.InternalObject, (after == null) ? System.Reflection.Missing.Value : after.InternalObject });
        }
Example #21
0
        /// <summary>
        /// Creates a merged cell from the specified Range object.
        /// </summary>
        /// <param name="across">True to merge cells in each row of the specified range as separate merged cells. The default value is False.</param>
        public void Merge(bool?across)
        {
            List <object> parms = new List <object>();

            if (across != null)
            {
                parms.Add(across.Value);
            }

            InternalObject.GetType().InvokeMember("Merge", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, parms.ToArray());
        }
        /// <summary>
        /// Deletes the specified ContentControl.
        /// </summary>
        /// <param name="deleteContents">Specifies whether to delete the contents of the content control. True removes both the content control and its contents. False removes the control but leaves the contents of the content control in the active document. The default value is False.</param>
        public void Delete(bool?deleteContents)
        {
            List <object> args = new List <object>();

            if (deleteContents.HasValue)
            {
                args.Add(deleteContents.Value);
            }

            InternalObject.GetType().InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, args.ToArray());
        }
Example #23
0
        public InternalObject SetStartRelativeToParent(int newStartRelativeToParent)
        {
            if (newStartRelativeToParent == StartRelativeToParent)
            {
                return(this);
            }
            InternalObject obj = (InternalObject)MemberwiseClone();

            obj.StartRelativeToParent = newStartRelativeToParent;
            return(obj);
        }
Example #24
0
        /// <summary>
        /// Adds a new Field to this collection.
        /// </summary>
        /// <param name="name">Name of the field to add</param>
        /// <param name="dataType">Data type of the field to add</param>
        /// <param name="size">Size of the field to add</param>
        /// <param name="fieldAttributes">Attributes on the field to add</param>
        public void Append(string name, DataType dataType, long?size, FieldAttribute?fieldAttributes)
        {
            List <object> parms = new List <object>();

            parms.Add(name);
            parms.Add(dataType);
            parms.Add(size);
            parms.Add(fieldAttributes);

            InternalObject.GetType().InvokeMember("Append", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, parms.ToArray());
        }
Example #25
0
        /// <summary>
        /// Deletes the object.
        /// </summary>
        /// <param name="shift">Used only with Range objects. Specifies how to shift cells to replace deleted cells. Can be one of the following DeleteShiftDirection constants: ToLeft or Up.
        /// If this argument is omitted, Microsoft Excel decides based on the shape of the range.</param>
        public void Delete(DeleteShiftDirection?shift)
        {
            List <object> parms = new List <object>();

            if (shift != null)
            {
                parms.Add(shift.Value);
            }

            InternalObject.GetType().InvokeMember("Delete", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, parms.ToArray());
        }
Example #26
0
        /// <summary>
        /// Gets a Border object that represents one of the borders of either a range of cells or a style. This object is internally cached and does not need to be manually disposed.
        /// </summary>
        /// <param name="idx">A variable that represents a Borders object.</param>
        /// <returns>Border</returns>
        public Border this[BordersIndex idx]
        {
            get
            {
                if (!_this.ContainsKey(idx))
                {
                    _this.Add(idx, new Border(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { idx })));
                }

                return(_this[idx]);
            }
        }
Example #27
0
        private void TrySave(string filename = null)
        {
            filename ??= FileName;

            using Stream outputStream = new FileStream(filename, FileMode.Create);

            InternalObject.Save(outputStream);
            _newGraphDirty = false;
            FileName       = filename;

            SaveToOriginal();
        }
Example #28
0
        /// <summary>
        /// Closes the document.
        /// </summary>
        /// <param name="saveChanges">Saves changes if true, abandons them if false, and asks the user if null</param>
        public void Close(bool?saveChanges)
        {
            List <object> parms = new List <object>();

            if (saveChanges != null)
            {
                parms.Add(saveChanges.Value);
            }

            InternalObject.GetType().InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, parms.ToArray());

            Dispose(true);
        }
Example #29
0
        public void Sort(Range key1 = null, SortOrder?order1 = null, Range key2 = null, SortType?type = null, SortOrder?order2 = null, Range key3 = null, SortOrder?order3 = null, YesNoGuess?header = YesNoGuess.No)
        {
            //if (!(key1 is String) && !(key1 is Range) && key1 != null)
            //    throw new ArgumentException("Key1 must be a string (range named) or a range object");

            //if (!(key2 is String) && !(key2 is Range) && key2 != null)
            //    throw new ArgumentException("Key2 must be a string (range named) or a range object");

            //if (!(key3 is String) && !(key3 is Range) && key3 != null)
            //    throw new ArgumentException("Key3 must be a string (range named) or a range object");

            InternalObject.GetType().InvokeMember("Sort", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, ComArguments.Prepare(key1, order1, key2, order2, key3, order3, header));
        }
Example #30
0
 /// <summary>
 /// Index the Recipients collection to get a recipient
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public Recipient this[int key]
 {
     get
     {
         try
         {
             return(new Recipient(InternalObject.GetType().InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { key })));
         }
         catch (Exception ex)
         {
             throw new IndexOutOfRangeException(String.Concat("Could not find recipient '", key, "'."), ex);
         }
     }
 }