示例#1
0
 public static tableStyleRowSetter RowMetaSet(this DataTable dc, tableStyleRowSetter default_table_metarows)
 {
     if (!dc.ExtendedProperties.ContainsKey(templateFieldDataTable.table_metarows))
     {
         dc.ExtendedProperties.add(templateFieldDataTable.table_metarows, default_table_metarows);
     }
     return(dc.ExtendedProperties[templateFieldDataTable.table_metarows] as tableStyleRowSetter);
 }
        /// <summary>
        /// Deploys the style.
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="ws">The ws.</param>
        /// <param name="useMetaSetFromTheTable">if set to <c>true</c> it will use style set from the table specified.</param>
        public void DeployStyle(DataTable table, ExcelWorksheet ws, Boolean useMetaSetFromTheTable = false)
        {
            int rc = ws.Dimension.Rows;

            if (rc > ROW_LIMIT_TODISABLE_STYLING)
            {
            }
            else
            {
                for (int i = 0; i < rc; i++)
                {
                    var ex_row = ws.Row(i + 1);
                    var in_row = table.Rows[i];
                    if (i > ROW_LIMIT_FOR_STYLE)
                    {
                        break;
                    }
                    tableStyleRowSetter metaSet = null;

                    if (useMetaSetFromTheTable)
                    {
                        metaSet = table.GetRowMetaSet();
                    }
                    DeployStyleToRow(ex_row, in_row, ws, metaSet);
                }
            }

            foreach (DataColumn dc in table.Columns)
            {
                ws.Column(dc.Ordinal + 1).Width = dc.GetWidth();

                switch (dc.GetImportance())
                {
                case dataPointImportance.alarm:
                    ws.Column(dc.Ordinal + 1).Style.Font.Color.SetColor(System.Drawing.Color.Red);
                    break;

                case dataPointImportance.important:
                    ws.Column(dc.Ordinal + 1).Style.Font.Bold = true;
                    break;

                case dataPointImportance.none:
                    break;

                case dataPointImportance.normal:
                    break;
                }
            }
        }
示例#3
0
 public static DataTable SetRowMetaSet(this DataTable dc, tableStyleRowSetter table_metarows)
 {
     dc.ExtendedProperties.add(templateFieldDataTable.table_metarows, table_metarows);
     return(dc);
 }
        /// <summary>
        /// Deploys the style to row.
        /// </summary>
        /// <param name="ex_row">The ex row.</param>
        /// <param name="in_row">The in row.</param>
        /// <param name="ws">The ws.</param>
        /// <param name="metaSet">The meta set.</param>
        public void DeployStyleToRow(ExcelRow ex_row, DataRow in_row, ExcelWorksheet ws, tableStyleRowSetter metaSet = null)
        {
            DataRowInReportTypeEnum style = DataRowInReportTypeEnum.data;

            if (extraRowStyles.ContainsKey(in_row))
            {
                style = extraRowStyles[in_row];
            }

            bool isEven = ((in_row.Table.Rows.IndexOf(in_row) % 2) > 0);

            Boolean isLegend = in_row.Table.TableName == LEGENDTABLE_NAME;

            var baseStyle = styleSet.rowStyles[style];

            var rowsMetaSet = this.GetRowMetaSet();

            if (metaSet != null)
            {
                rowsMetaSet = metaSet;
            }

            var response = rowsMetaSet.evaluate(in_row, this, baseStyle);

            if (response != null)
            {
                if (response.style != null)
                {
                    baseStyle = response.style;
                }
            }
            if (baseStyle == null)
            {
                baseStyle = styleSet.rowStyles[style];
            }
            foreach (string s in response.notes)
            {
                Console.WriteLine(s);
            }

            ex_row.SetStyle(baseStyle, isEven);

            switch (style)
            {
            case DataRowInReportTypeEnum.columnCaption:
                if (!isLegend)
                {
                    foreach (var cpair in categories)
                    {
                        foreach (selectZone zone in categories.categoryZones[cpair.Key])
                        {
                            var sl = ws.getExcelRange(ex_row, zone);
                            sl.Style.Fill.PatternType = ExcelFillStyle.Solid;

                            var col = categories.categoryColors[cpair.Key];     //.First().DefaultBackground(System.Drawing.Color.Gray);
                            sl.Style.Fill.BackgroundColor.SetColor(col);
                            sl.Style.Fill.BackgroundColor.Tint = new decimal(0.2);
                        }
                    }
                }
                break;

            case DataRowInReportTypeEnum.mergedHeaderTitle:
                ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true;

                break;

            case DataRowInReportTypeEnum.mergedHeaderInfo:

                ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true;

                break;

            case DataRowInReportTypeEnum.mergedFooterInfo:

                ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true;

                break;

            case DataRowInReportTypeEnum.mergedHorizontally:

                selectZone z   = new selectZone(0, 0, Columns.Count - 1, 0);
                var        s2l = ws.getExcelRange(ex_row, z);
                s2l.Merge = true;
                break;

            case DataRowInReportTypeEnum.mergedCategoryHeader:

                double tn   = 0.2;
                int    hlip = -1;
                foreach (var cpair in categories)
                {
                    if (hlip == -1)
                    {
                        tn = 0.3;
                    }
                    else
                    {
                        tn = 0.6;
                    }

                    foreach (selectZone zone in categories.categoryZones[cpair.Key])
                    {
                        var sl = ws.getExcelRange(ex_row, zone);
                        sl.Merge = true;
                        sl.Value = cpair.Key.ToUpper();
                        sl.Style.Fill.PatternType = ExcelFillStyle.Solid;

                        var col = categories.categoryColors[cpair.Key];     //.First().DefaultBackground(System.Drawing.Color.Gray);
                        sl.Style.Fill.BackgroundColor.SetColor(col);
                        sl.Style.Fill.BackgroundColor.Tint = new decimal(tn);
                    }

                    hlip = -hlip;
                }
                isEven = !isEven;

                break;

            case DataRowInReportTypeEnum.data:

                //ex_row.Style.Font.Size = 9;

                foreach (DataColumn dc in in_row.Table.Columns)
                {
                    string format   = dc.GetFormatForExcel();
                    var    aligment = dc.GetAligment();

                    ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = aligment.GetHorizontalAlignment();


                    if (!format.isNullOrEmpty())
                    {
                        ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.Numberformat.Format = format;
                    }

                    //if (dc.GetValueType().isNumber())
                    //{
                    //    ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                    //}
                    //else if (dc.GetValueType().IsEnum)
                    //{
                    //    ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    //}
                    //else if (dc.GetValueType().isBoolean())
                    //{
                    //    ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
                    //}
                    //else
                    //{
                    //    ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
                    //}
                }

                break;
            }

            if (!isLegend)
            {
                if (ex_row.Row == (RowStart + RowsWithMaxAggregation))
                {
                    ex_row.Style.Border.Bottom.Style = ExcelBorderStyle.Dotted;
                    ex_row.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Red);
                }
            }
        }