Esempio n. 1
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                //writer.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);
                writer.AddCell(ColSpan, RowSpan);
                writer.SetValue(Value);
                if (Width != null)
                {
                    writer.SetColumnWidth((int)Width);
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 2
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                if (Items.Count == 0)
                {
                    writer.AddCell(ColSpan, writer.EndRowIndex - writer.CurrentRowIndex);
                }
                else
                {
                    writer.AddCell(GetCols());
                }

                // writer.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);
                writer.SetValue(Text);

                using (var rowWriter = writer.AddRowArea())
                {
                    foreach (var item in Items)
                    {
                        if (item.GetRows() == 0)
                        {
                            continue;
                        }

                        using (var colWriter = rowWriter.AddColArea())
                        {
                            item.WriteTo(colWriter, param);
                        }
                    }
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 3
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                using (var rowWriter = writer.AddRowArea(GetRows(), GetCols()))
                {
                    var s = String.Empty;

                    foreach (var item in Items)
                    {
                        if (item is XlsDataField)
                        {
                            var field = (XlsDataField)item;
                            var val   = field.GetValue();
                            var type  = field.Field.GetDataType();
                            if (val != null)
                            {
                                switch (type)
                                {
                                case BaseDataType.Text:
                                    s += (string)val;
                                    break;

                                case BaseDataType.Int:
                                    s += ((int)val).ToString();
                                    break;

                                case BaseDataType.Float:
                                    s += ((double)val).ToString("F");
                                    break;

                                case BaseDataType.Currency:
                                    s += ((decimal)val).ToString("N");
                                    break;

                                case BaseDataType.DateTime:
                                    s += ((DateTime)val).ToShortDateString();
                                    break;

                                case BaseDataType.Bool:
                                    s += ((bool)val) ? "Да" : "Нет";
                                    break;

                                default:
                                    s += val.ToString();
                                    break;
                                }
                            }
                        }
                        else if (item is XlsCell)
                        {
                            var val = ((XlsCell)item).GetValue();
                            s += val != null?val.ToString() : String.Empty;
                        }
                        else if (item is XlsNode)
                        {
                            if (item is XlsTextNode)
                            {
                                s += ((XlsTextNode)item).Text;
                            }
                            else if (item is XlsCellNode)
                            {
                                var val = ((XlsCellNode)item).Cell.GetValue();
                                s += val != null?val.ToString() : String.Empty;
                            }
                        }
                    }
                    rowWriter.AddCell(GetCols(), GetRows());
                    writer.SetValue(s);
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 4
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                var value = param == XlsGrid.WriteSummaryRow
                    ? SummaryValueCount > 0 ? GetSummaryValue() : ""
                    : GetValue();
                var type = Field.GetDataType();

                // writer.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);
                writer.ShrinkToFit = ShrinkToFit;
                writer.AddCell(ColSpan, RowSpan);

                if (value != null)
                {
                    var s = value.ToString();
                    if (type == BaseDataType.Int)
                    {
                        int i;
                        if (value is int)
                        {
                            writer.SetValue((int)value);
                            SummaryValue += (int)value;
                            SummaryValueCount++;
                        }
                        else if (int.TryParse(s, out i))
                        {
                            writer.SetValue(i);
                            SummaryValue += i;
                            SummaryValueCount++;
                        }
                        else
                        {
                            writer.SetValue(s);
                        }
                    }
                    else if (type == BaseDataType.Float || type == BaseDataType.Currency)
                    {
                        double d;
                        if (value is double)
                        {
                            writer.SetValue((double)value);
                            SummaryValue += (double)value;
                            SummaryValueCount++;
                        }
                        else if (value is float)
                        {
                            d = Convert.ToDouble(value);
                            writer.SetValue(d);
                            SummaryValue += d;
                            SummaryValueCount++;
                        }
                        else if (value is decimal)
                        {
                            d = Convert.ToDouble(value);
                            writer.SetValue(d);
                            SummaryValue += d;
                            SummaryValueCount++;
                        }
                        else if (value is int)
                        {
                            d = Convert.ToDouble(value);
                            writer.SetValue(d);
                            SummaryValue += d;
                            SummaryValueCount++;
                        }
                        else if (double.TryParse(s, out d))
                        {
                            writer.SetValue(d);
                            SummaryValue += d;
                            SummaryValueCount++;
                        }
                        else
                        {
                            writer.SetValue(s);
                        }
                    }
                    else if (type == BaseDataType.DateTime)
                    {
                        DateTime dt;
                        if (value is DateTime)
                        {
                            writer.SetValue((DateTime)value);
                        }
                        else if (DateTime.TryParse(s, out dt))
                        {
                            writer.SetValue(dt);
                        }
                        else
                        {
                            writer.SetValue(s);
                        }
                    }
                    else if (type == BaseDataType.Bool)
                    {
                        bool b;
                        if (value is bool)
                        {
                            writer.SetValue((bool)value);
                        }
                        else if (bool.TryParse(s, out b))
                        {
                            writer.SetValue(b);
                        }
                        else
                        {
                            writer.SetValue(s);
                        }
                    }
                    else
                    {
                        writer.SetValue(s);
                    }

                    /*{
                     *  case CissaDataType.Text:
                     *      writer.SetValue(value.ToString());
                     *      break;
                     *  case CissaDataType.Int:
                     *      writer.SetValue((int) value);
                     *      break;
                     *  case CissaDataType.Float:
                     *      writer.SetValue((double) value);
                     *      break;
                     *  case CissaDataType.Currency:
                     *      writer.SetValue(Convert.ToDouble(value));
                     *      break;
                     *  case CissaDataType.DateTime:
                     *      writer.SetValue((DateTime) value);
                     *      break;
                     *  case CissaDataType.Bool:
                     *      writer.SetValue((bool) value);
                     *      break;
                     *  default:
                     *      writer.SetValue(value);
                     *      break;
                     * }*/
                }
                if (Width != null)
                {
                    writer.SetColumnWidth((int)Width);
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }