예제 #1
0
        /// <summary>
        /// Creates a single export settings for the current selection.
        /// </summary>
        public static SingleExportSettings CreateForSelection(Preset preset)
        {
            SelectionViewModel svm = new SelectionViewModel(Instance.Default.Application);
            // If the ActiveChart property of the Excel application is not null,
            // either a chart or 'something in the chart' is selected. To make sure
            // we don't attempt to export 'something in the chart', we select the
            // entire chart.
            // If there is no workbook open, accessing the ActiveChart property causes
            // a COM exception.
            object activeChart = null;

            try
            {
                activeChart = Instance.Default.Application.ActiveChart;
            }
            catch (System.Runtime.InteropServices.COMException) { }
            finally
            {
                if (activeChart != null)
                {
                    ChartViewModel cvm = new ChartViewModel(activeChart as Chart);
                    // Handle chart sheets and embedded charts differently
                    cvm.SelectSpecial();
                }
            }
            if (svm.Selection != null)
            {
                return(new SingleExportSettings(preset, svm.Bounds.Width, svm.Bounds.Height));
            }
            else
            {
                return(new SingleExportSettings());
            }
        }