Ejemplo n.º 1
0
        public void DimensionsChartSheet()
        {
            Chart  c      = Instance.Default.Application.ActiveWorkbook.Charts.Add();
            Preset preset = PresetsRepository.Default.First;
            SingleExportSettings settings = SingleExportSettings.CreateForSelection(preset);

            svm = new SingleExportSettingsViewModel(settings);
            // Assert small differences because rounding errors are possible
            Assert.IsTrue(Math.Abs(c.ChartArea.Width - svm.Width) < 0.000001,
                          "Export settings width is incorrect.");
            Assert.IsTrue(Math.Abs(c.ChartArea.Height - svm.Height) < 0.000001,
                          "Export settings height is incorrect.");
        }
Ejemplo n.º 2
0
        public void ExportCommandDisabledWithoutSelection()
        {
            Instance.Default.Reset(); // reset Excel; no workbooks open

            Preset preset = PresetsRepository.Default.First;
            SingleExportSettings          settings = SingleExportSettings.CreateForSelection(preset);
            SingleExportSettingsViewModel svm      = new SingleExportSettingsViewModel(settings);

            Assert.IsFalse(svm.ExportCommand.CanExecute(null),
                           "Export command should be disabled if there is no selection.");
            Instance.Default.CreateWorkbook();
            settings = SingleExportSettings.CreateForSelection(preset);
            svm      = new SingleExportSettingsViewModel(settings);
            Assert.IsTrue(svm.ExportCommand.CanExecute(null),
                          "Export command should be enabled if something is selected.");
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            Workbook     wb  = Instance.Default.CreateWorkbook();
            Worksheet    ws  = wb.Worksheets[1];
            ChartObjects cos = ws.ChartObjects();

            cos.Add(10, 10, 300, 200).Select();
            // Get a preset from the UserSettings to enforce the settings are loaded now.
            Preset preset = UserSettings.UserSettings.Default.ExportPresets.FirstOrDefault();

            if (preset == null)
            {
                preset = PresetsRepository.Default.First;
            }
            SingleExportSettings settings = SingleExportSettings.CreateForSelection(preset);

            svm = new SingleExportSettingsViewModel(settings);
        }
Ejemplo n.º 4
0
        static void ExportSelection()
        {
            Preset preset = UserSettings.UserSettings.Default.ExportPreset;

            if (preset == null)
            {
                preset = PresetsRepository.Default.First;
            }
            SingleExportSettings          settings = SingleExportSettings.CreateForSelection(preset);
            SingleExportSettingsViewModel vm       = new SingleExportSettingsViewModel(settings);

            vm.ShowProgressMessage.Sent    += Exporter_ShowProgress_Sent;
            vm.ProcessFinishedMessage.Sent += Exporter_ProcessFinished_Sent;
            vm.InjectInto <Export.Views.SingleExportSettingsView>().ShowDialogInForm();
            // NotificationAction a = new NotificationAction();
            // a.Caption = Strings.ScreenshotExport;
            // a.Message = Strings.GraphicHasNoCopyMethod;
            // a.Invoke();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Exports the current selection using the last settings, if available.
        /// </summary>
        public void ExportSelection()
        {
            Preset preset = Preset.FromLastUsed(Instance.Default.Application.ActiveWorkbook);

            Logger.Info("ExportSelection: Preset.FromLastUsed: {0}", preset);
            if (preset == null)
            {
                Dispatcher.Execute(Command.ExportSelection);
            }
            else
            {
                SingleExportSettings          settings = SingleExportSettings.CreateForSelection(preset);
                SingleExportSettingsViewModel svm      = new SingleExportSettingsViewModel(settings);
                svm.ChooseFileNameMessage.Sent  += ChooseFileNameMessage_Sent;
                svm.ShowProgressMessage.Sent    += Dispatcher.Exporter_ShowProgress_Sent;
                svm.ProcessFinishedMessage.Sent += Dispatcher.Exporter_ProcessFinished_Sent;
                if (svm.ChooseFileNameCommand.CanExecute(null))
                {
                    svm.ChooseFileNameCommand.Execute(null);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Exports the current selection to a graphic file.
        /// </summary>
        /// <param name="fileName">File name to export to. The file extension
        /// must be one of '.tif', '.tiff', '.png' or '.emf'.</param>
        /// <param name="dpi">Resolution in dots per inch (DPI).</param>
        /// <param name="colorSpace">Target color space (one of 'RGB', 'GRAY',
        /// 'MONO'; if this string is empty, 'RGB' will be assumed).
        /// Note: CMYK is currently not supported by this API function.
        /// </param>
        /// <param name="transparency">Transparency (one of 'NONE', 'CANVAS', 'WHITE';
        /// if this string is empty, 'NONE' will be assumed).
        /// </param>
        /// <returns>
        /// 0 if successful;
        /// 1 if unknown file type;
        /// 2 if unknown color space;
        /// 3 if unknown transparency type.
        /// </returns>
        public int ExportSelection(
            string fileName,
            int dpi,
            string colorSpace,
            string transparency)
        {
            Logger.Info("Export selection");
            string ext = System.IO.Path.GetExtension(fileName).ToUpper();

            FileType ft;

            switch (ext)
            {
            case ".TIF": ft = FileType.Tiff; break;

            case ".TIFF": ft = FileType.Tiff; break;

            case ".PNG": ft = FileType.Png; break;

            case ".EMF": ft = FileType.Emf; break;

            default: return(1);
            }

            ColorSpace cs;

            switch (colorSpace.ToUpper())
            {
            case "": cs = ColorSpace.Rgb; break;

            case "RGB": cs = ColorSpace.Rgb; break;

            case "GRAY": cs = ColorSpace.GrayScale; break;

            case "MONO": cs = ColorSpace.Monochrome; break;

            default: return(2);
            }

            Transparency t;

            switch (transparency.ToUpper())
            {
            case "": t = Transparency.TransparentCanvas; break;

            case "NONE": t = Transparency.WhiteCanvas; break;

            case "CANVAS": t = Transparency.TransparentCanvas; break;

            case "WHITE": t = Transparency.TransparentWhite; break;

            default: return(3);
            }

            Preset preset = new Preset(ft, dpi, cs);

            preset.Transparency = t;
            Logger.Info("Preset: {0}", preset);
            SingleExportSettings          settings = SingleExportSettings.CreateForSelection(preset);
            SingleExportSettingsViewModel vm       = new SingleExportSettingsViewModel(settings);

            vm.FileName = fileName;
            vm.ExportCommand.Execute(null);
            return(0); // success
        }