/// <summary>
        /// Добавить строку со значениями.
        /// </summary>
        /// <param name="row">Номер строки.</param>
        /// <param name="columnsCount">Количество колонок в области значений.</param>
        /// <param name="startColumn">Начальная колонка, для области значений.</param>
        static private void WriteDataRow(int row, int columnsCount, int startColumn)
        {
            int indexColumn = startColumn;

            for (int col = 0; col < columnsCount; col++)
            {
                CellData      cell      = pivotDataProvider.Provider.CellSet_Description.GetCellDescription(col, row);
                CellValueData valueData = cell.Value;

                string color     = string.Empty;
                object backColor = valueData.GetPropertyValue("BACK_COLOR");
                if (backColor != null)
                {
                    int colorARGB = Convert.ToInt32(backColor);
                    int colorOLE  = ColorTranslator.ToOle(Color.FromArgb(colorARGB));
                    color = "#" + Color.FromArgb(colorOLE).Name;
                }

                string value = string.Empty;
                string type  = "String";
                if (valueData.Value != null)
                {
                    type  = GetTypeForExcel(valueData.Value);
                    value = valueData.Value.ToString();
                    value = value.Replace(',', '.');
                }

                string numberFormate = string.Empty;
                if (valueData.GetPropertyValue("FORMAT_STRING") != null)
                {
                    numberFormate = valueData.GetPropertyValue("FORMAT_STRING").ToString();
                }
                if (numberFormate == "Currency" || (String.IsNullOrEmpty(numberFormate) && type == "Number"))
                {
                    numberFormate = GetNumberFormat(valueData.DisplayValue);
                }

                string styleId = defaultStyle;
                if (valueData.Value != null)
                {
                    styleId = FindStyle(color, numberFormate, !cell.Value.CanUpdate);
                }



                if (string.IsNullOrEmpty(styleId))
                {
                    styleId = "Style" + row + col;
                    AddStyle(styleId, color, numberFormate, !cell.Value.CanUpdate, true, fontTahoma8);
                }

                WriteCell(value, type, styleId, indexColumn, false);
                indexColumn++;
            }
        }
Esempio n. 2
0
 public Set(string sId, CellValueData cell)
     : base(sId)
 {
     CellValue = cell;
 }
        public CellValueData GetValue(params int[] index)
        {
            if (CS == null)
            {
                return(CellValueData.Empty);
            }

            int[] indexVector = new int[CS.Axes.Count];
            for (int i = 0; i < indexVector.Length; i++)
            {
                indexVector[i] = 0;
            }
            index.CopyTo(indexVector, 0);

            Cell cell = null;

            try
            {
                cell = CS[indexVector];
            }
            catch (ArgumentOutOfRangeException)
            {
                return(CellValueData.Empty);
            }
            if (cell != null)
            {
                object value       = null;
                string displayName = string.Empty;

                try
                {
                    displayName = cell.FormattedValue;
                }
                catch (Exception exc)
                {
                    displayName = CellValueData.ERROR;
                }

                try
                {
                    value = cell.Value;
                }
                catch (Exception exc)
                {
                    value = exc.ToString();
                }

                if (string.IsNullOrEmpty(displayName))
                {
                    if (value == null)
                    {
                        displayName = String.Empty;
                    }
                    else
                    {
                        displayName = value.ToString();
                    }
                }

                CellValueData res = new CellValueData(value, displayName);

                foreach (CellProperty prop in cell.CellProperties)
                {
                    PropertyData property = new PropertyData(prop.Name, null);
                    try
                    {
                        property.Value = prop.Value;
                    }
                    catch (Microsoft.AnalysisServices.AdomdClient.AdomdErrorResponseException ex)
                    {
                        property.Value = ex.ToString();
                    }
                    res.Properties.Add(property);
                }

                return(res);
            }

            return(null);
        }