/// <summary>
 /// Get friendly name of this action.
 /// </summary>
 /// <returns>friendly name of this action.</returns>
 public override string GetName()
 {
     return("Set Cells Format: " + format.ToString());
 }
Beispiel #2
0
        public void LoadPage()
        {
            var sheet = this.grid.CurrentWorksheet;

            sheet.IterateCells(sheet.SelectionRange, (r, c, cell) =>
            {
                if (backupFormat == CellDataFormatFlag.General)
                {
                    sampleCell = cell.Clone();
                    unvell.ReoGrid.Utility.CellUtility.CopyCellContent(sampleCell, cell);

                    if (cell != null)
                    {
                        originalData = cell.Data;
                    }

                    backupFormat = cell.DataFormat;
                    return(true);
                }
                else if (backupFormat == cell.DataFormat)
                {
                    return(true);
                }
                else
                {
                    backupFormat = CellDataFormatFlag.General;
                    return(false);
                }
            });

            currentFormat = backupFormat;

            backupFormatArgs = null;

            if (currentFormat != CellDataFormatFlag.General)
            {
                switch (currentFormat)
                {
                case CellDataFormatFlag.Number:
                    if ((sampleCell.DataFormatArgs
                         ?? new NumberDataFormatter.NumberFormatArgs())
                        is NumberDataFormatter.NumberFormatArgs nargs)
                    {
                        numberDecimalPlaces.Value     = nargs.DecimalPlaces;
                        chkNumberUseSeparator.Checked = nargs.UseSeparator;
                        foreach (NegativeStyleListItem item in numberNegativeStyleList.Items)
                        {
                            if (item.NegativeStyle == nargs.NegativeStyle)
                            {
                                numberNegativeStyleList.SelectedItem = item;
                                break;
                            }
                        }
                    }
                    backupFormatArgs = Clone(sampleCell.DataFormatArgs);
                    break;

                case CellDataFormatFlag.DateTime:
                    DateTimeDataFormatter.DateTimeFormatArgs dargs = (DateTimeDataFormatter.DateTimeFormatArgs)sampleCell.DataFormatArgs;

                    foreach (var item in datetimeLocationList.Items)
                    {
                        if (string.Compare(((CultureInfo)item).IetfLanguageTag, dargs.CultureName, true) == 0)
                        {
                            datetimeLocationList.SelectedItem = item;
                            break;
                        }
                    }

                    txtDatetimeFormat.Text = dargs.Format;

                    object df = null;
                    foreach (var item in datetimeFormatList.Items)
                    {
                        if (((DatetimeFormatListItem)item).Pattern.Equals(dargs.Format, StringComparison.CurrentCultureIgnoreCase))
                        {
                            df = item;
                            break;
                        }
                    }
                    datetimeFormatList.SelectedItem = df;
                    backupFormatArgs = Clone(sampleCell.DataFormatArgs);
                    break;

                case CellDataFormatFlag.Currency:
                    var cargs = (CurrencyDataFormatter.CurrencyFormatArgs)sampleCell.DataFormatArgs;

                    foreach (var item in currencySymbolList.Items)
                    {
                        if (string.Compare(((CurrencySymbolListItem)item).Culture.IetfLanguageTag, cargs.CultureEnglishName, true) == 0)
                        {
                            currencySymbolList.SelectedItem = item;
                            break;
                        }
                    }

                    currencyDecimalPlaces.Value = cargs.DecimalPlaces;

                    foreach (NegativeStyleListItem item in currencyNegativeStyleList.Items)
                    {
                        if (item.NegativeStyle == cargs.NegativeStyle)
                        {
                            currencyNegativeStyleList.SelectedItem = item;
                            break;
                        }
                    }

                    backupFormatArgs = Clone(sampleCell.DataFormatArgs);
                    break;

                case CellDataFormatFlag.Percent:
                    if ((sampleCell.DataFormatArgs
                         ?? new NumberDataFormatter.NumberFormatArgs())
                        is NumberDataFormatter.NumberFormatArgs pargs)
                    {
                        percentDecimalPlaces.Value = pargs.DecimalPlaces;
                    }
                    backupFormatArgs = Clone(sampleCell.DataFormatArgs);
                    break;
                }

                for (int i = 0; i < formatList.Items.Count; i++)
                {
                    var item = formatList.Items[i].ToString();

                    if (string.Equals(item, currentFormat.ToString(), StringComparison.CurrentCultureIgnoreCase))
                    {
                        formatList.SelectedIndex = i;
                        break;
                    }
                }
            }
            else
            {
                formatList.SelectedIndex = 0;
            }

            backupFormat = currentFormat;
        }