예제 #1
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="range">The range into which to insert the picture</param>
        /// <param name="fillRange">Should the image fill the range? If not, it will just use the range as a starting point, and will use its native size.</param>
        /// <returns></returns>
        public Shape AddPicture(string filename, bool linkToFile, bool saveWithDocument, Range range, bool fillRange)
        {
            if (!File.Exists(filename))
                throw new FileNotFoundException("Could not find file " + filename);

            double width, height;
            if (fillRange)
            {
                width = range.Width;
                height = range.Height;
            }
            else
            {
                using (var img = Image.FromFile(filename))
                {
                    using (var g = Graphics.FromImage(img))
                    {
                        width = img.Width * POINTS_PER_INCH / g.DpiX;
                        height = img.Height * POINTS_PER_INCH / g.DpiY;
                    }
                }
            }

            return AddPicture(filename, linkToFile, saveWithDocument, range.Left, range.Top, width, height);
        }
예제 #2
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;
        }
예제 #3
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));
        }
예제 #4
0
 public string Address(bool rowAbsolute = true, bool columnAbsolute = true, XLReferenceStyle referenceStyle = XLReferenceStyle.xlA1, bool external = false, Range relativeTo = null)
 {
     return InternalObject.GetType().InvokeMember("Address", System.Reflection.BindingFlags.GetProperty, null, InternalObject, new object[] { rowAbsolute, columnAbsolute, referenceStyle, external, (relativeTo == null) ? System.Reflection.Missing.Value : relativeTo.InternalObject }).ToString();
 }
예제 #5
0
        internal override void Dispose(bool disposing)
        {
            if (_comment != null)
            {
                _comment.Dispose();
                _comment = null;
            }

            if (_font != null)
            {
                _font.Dispose();
                _font = null;
            }

            if (_borders != null)
            {
                _borders.Dispose();
                _borders = null;
            }

            if (_columns != null)
            {
                _columns.Dispose();
                _columns = null;
            }

            if (_rows != null)
            {
                _rows.Dispose();
                _rows = null;
            }

            if (_entireColumn != null)
            {
                _entireColumn.Dispose();
                _entireColumn = null;
            }

            if (_entireRow != null)
            {
                _entireRow.Dispose();
                _entireRow = null;
            }

            if (_worksheet != null)
            {
                _worksheet.Dispose();
                _worksheet = null;
            }

            if (_application != null)
            {
                _application.Dispose();
                _application = null;
            }

            base.Dispose(disposing);
        }
예제 #6
0
 public void Copy(Range Destination = null)
 {
     InternalObject.GetType().InvokeMember("Copy", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { Destination });
 }
예제 #7
0
        internal override void Dispose(bool disposing)
        {
            if (_cells != null)
            {
                _cells.Dispose();
                _cells = null;
            }

            if (_columns != null)
            {
                _columns.Dispose();
                _columns = null;
            }

            if (_pictures != null)
            {
                _pictures.Dispose();
                _pictures = null;
            }

            if (_shapes != null)
            {
                _shapes.Dispose();
                _shapes = null;
            }

            if (_rows != null)
            {
                _rows.Dispose();
                _rows = null;
            }

            if (_pageSetup != null)
            {
                _pageSetup.Dispose();
                _shapes = null;
            }

            if (_chartobjects != null)
            {
                _chartobjects.Dispose();
                _chartobjects = null;
            }

            if (_hyperlinks != null)
            {
                _hyperlinks.Dispose();
                _hyperlinks = null;
            }

            base.Dispose(disposing);
        }
예제 #8
0
 /// <summary>
 /// Pastes the contents of the Clipboard onto the sheet, at the given location.
 /// </summary>
 /// <param name="destination">A Range object representing the location at which to paste.</param>
 public void Paste(Range destination)
 {
     InternalObject.GetType().InvokeMember("Paste", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { destination.InternalObject });
 }
예제 #9
0
 /// <summary>
 /// Adds a hyperlink to the specified range or shape. The returned hyperlink must be manually disposed.
 /// </summary>
 /// <param name="anchor">The anchor for the hyperlink. Can be either a Range or Shape object.</param>
 /// <param name="address">The address of the hyperlink.</param>
 /// <param name="subAddress">The subaddress of the hyperlink.</param>
 /// <param name="screenTip">The screen tip to be displayed when the mouse pointer is paused over the hyperlink.</param>
 /// <param name="textToDisplay">The text to be displayed for the hyperlink.</param>
 /// <returns>A reference to the new Hyperlink</returns>
 public Hyperlink Add(Range anchor, string address, string subAddress = null, string screenTip = null, string textToDisplay = null)
 {
     return(Add(anchor.InternalObject, address, subAddress, screenTip, textToDisplay));
 }
 /// <summary>
 /// Adds one or more new series to the SeriesCollection collection.
 /// </summary>
 /// <param name="Source">The new data as a Range object.</param>
 /// <param name="rowcol">Specifies whether the new values are in the rows or columns of the specified range.</param>
 /// <param name="serieslabels">True if the first row or column contains the name of the data series. False if the first row or column contains the first data point of the series. If this argument is omitted, Microsoft Excel attempts to determine the location of the series name from the contents of the first row or column.</param>
 /// <param name="categoryLabels">True if the first row or column contains the name of the category labels. False if the first row or column contains the first data point of the series. If this argument is omitted, Microsoft Excel attempts to determine the location of the category label from the contents of the first row or column.</param>
 /// <param name="replace">If CategoryLabels is True and Replace is True, the specified categories replace the categories that currently exist for the series. If Replace is False, the existing categories will not be replaced. The default value is False.</param>
 /// <returns></returns>
 public Series Add(Range Source, RowCol? rowcol = null, bool? serieslabels = null, bool? categoryLabels = null, bool? replace = null)
 {
     return new Series(InternalObject.GetType().InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { Source, rowcol, serieslabels, categoryLabels, replace }));
 }
예제 #11
0
 /// <summary>
 /// Adds a hyperlink to the specified range or shape. The returned hyperlink must be manually disposed.
 /// </summary>
 /// <param name="anchor">The anchor for the hyperlink. Can be either a Range or Shape object.</param>
 /// <param name="address">The address of the hyperlink.</param>
 /// <param name="subAddress">The subaddress of the hyperlink.</param>
 /// <param name="screenTip">The screen tip to be displayed when the mouse pointer is paused over the hyperlink.</param>
 /// <param name="textToDisplay">The text to be displayed for the hyperlink.</param>
 /// <returns>A reference to the new Hyperlink</returns>
 public Hyperlink Add(Range anchor, string address, string subAddress = null, string screenTip = null, string textToDisplay = null)
 {
     return Add(anchor.InternalObject, address, subAddress, screenTip, textToDisplay);
 }
예제 #12
0
        /// <summary>
        /// Sets the source data range for the chart.
        /// </summary>
        /// <param name="source">The range that contains the source data.</param>
        /// <param name="plotBy">Specifies the way the data is to be plotted.</param>
        public void SetSourceData(Range source, RowCol plotBy)
        {
            var missing = System.Reflection.Missing.Value;

            InternalObject.GetType().InvokeMember("SetSourceData", System.Reflection.BindingFlags.InvokeMethod, null, InternalObject, new object[] { (source != null ? source.InternalObject : missing), (int)plotBy });
        }
예제 #13
0
        /// <summary>
        /// Adds a picture to the spreadsheet. The returned shape object must be manually disposed.
        /// </summary>
        /// <param name="img">The image to add</param>
        /// <param name="origin">The range at which to put the top left corner of the image.</param>
        /// <param name="width">Width, in points.</param>
        /// <param name="height">Height, in points.</param>
        /// <returns></returns>
        public Shape AddPicture(Image img, Range origin, double width, double height)
        {
            string tempFile = Path.GetTempFileName();
            File.Move(tempFile, tempFile = tempFile + ".bmp");

            img.Save(tempFile, System.Drawing.Imaging.ImageFormat.Bmp);

            Shape shape = AddPicture(tempFile, false, true, origin, width, height);

            File.Delete(tempFile);

            return shape;
        }
예제 #14
0
        /// <summary>
        /// Adds a picture to the spreadsheet. The returned shape object must be manually disposed.
        /// </summary>
        /// <param name="img">The image to add</param>
        /// <param name="range">The range into which to insert the picture</param>
        /// <param name="fillRange">Should the image fill the range? If not, it will just use the range as a starting point, and will use its native size.</param>
        /// <returns></returns>
        public Shape AddPicture(Image img, Range range, bool fillRange)
        {

            string tempFile = Path.GetTempFileName();
            File.Move(tempFile, tempFile = tempFile + ".bmp");

            img.Save(tempFile, System.Drawing.Imaging.ImageFormat.Bmp);

            Shape shape = AddPicture(tempFile, false, true, range, fillRange);

            File.Delete(tempFile);

            return shape;
        }
예제 #15
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="origin">The range at which to put the top left corner of the image.</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, Range origin, double width, double height)
        {
            if (!File.Exists(filename))
                throw new FileNotFoundException("Could not find file " + filename);

            return AddPicture(filename, linkToFile, saveWithDocument, origin.Left, origin.Top, width, height);
        }