Beispiel #1
0
        /// <summary>
        /// rebuild the parameter sheet, replace it if it already exists.
        /// </summary>
        /// <param name="application">
        /// The excel application object that contains the <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="clones">
        /// The <see cref="Thing"/>s that have been changed on the Parameter sheet that need to be kept
        /// </param>
        public void Rebuild(Application application, Workbook workbook, IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
        {
            var sw = new Stopwatch();

            sw.Start();

            this.excelApplication = application;

            this.excelApplication.StatusBar = "Rebuilding Parameter Sheet";

            this.listSeparator = (string)application.International(XlApplicationInternational.xlListSeparator);
            this.xlCountryCode = Convert.ToInt32(application.International(XlApplicationInternational.xlCountryCode));
            this.SetLanguageSpecificVariables();
            this.SetSwitchString();

            var enabledEvents  = application.EnableEvents;
            var displayAlerts  = application.DisplayAlerts;
            var screenupdating = application.ScreenUpdating;
            var calculation    = application.Calculation;

            application.EnableEvents   = false;
            application.DisplayAlerts  = false;
            application.Calculation    = XlCalculation.xlCalculationManual;
            application.ScreenUpdating = false;

            try
            {
                application.Cursor = XlMousePointer.xlWait;

                this.parameterSheet = ParameterSheetUtilities.RetrieveParameterSheet(workbook, true);

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, false);

                this.PopulateSheetArrays(processedValueSets);
                this.WriteParameterSheet();
                this.ApplySheetSettings();

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, true);

                this.excelApplication.StatusBar = $"CDP4: Parameter Sheet rebuilt in {sw.ElapsedMilliseconds} [ms]";
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                this.excelApplication.StatusBar = $"CDP4: The following error occured while rebuilding the sheet: {ex.Message}";
            }
            finally
            {
                application.EnableEvents   = enabledEvents;
                application.DisplayAlerts  = displayAlerts;
                application.Calculation    = calculation;
                application.ScreenUpdating = screenupdating;

                application.Cursor = XlMousePointer.xlDefault;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Queries the appropriate <see cref="NumberFormatInfo"/> based on the decimal separator and thousands separator of the excel application
        /// </summary>
        /// <param name="application">
        /// The current excel application object
        /// </param>
        /// <returns>
        /// an instance of <see cref="NumberFormatInfo"/>
        /// </returns>
        private NumberFormatInfo QuerayNumberFormatInfo(Application application)
        {
            NumberFormatInfo numberFormatInfo = null;

            if (application.UseSystemSeparators)
            {
                numberFormatInfo = ExcelNumberFormatProvider.CreateExcelNumberFormatInfo(true);
            }
            else
            {
                var decimalSeparator   = (string)application.International(XlApplicationInternational.xlDecimalSeparator);
                var thousandsSeparator = (string)application.International(XlApplicationInternational.xlThousandsSeparator);

                numberFormatInfo = ExcelNumberFormatProvider.CreateExcelNumberFormatInfo(false, decimalSeparator, thousandsSeparator);
            }

            return(numberFormatInfo);
        }