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

            try
            {
                using (var rowWriter = writer.AddRowArea(GetRows(), GetCols()))
                {
                    // rowWriter.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);

                    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. 2
0
        public void WriteTo(XlsWriter writer)
        {
            var oldStyle = writer.SetStyle(Style);

            try
            {
                if (DefaultRowHeight > 0)
                {
                    writer.DefaultRowHeight = DefaultRowHeight;
                }

                if (ColumnWidths != null)
                {
                    foreach (var columnWidth in ColumnWidths)
                    {
                        writer.SetColumnWidth(columnWidth.Key - 1, columnWidth.Value * 256);
                    }
                }
                foreach (var area in Areas)
                {
                    area.WriteTo(writer);
                }
                writer.ApplyColumnAutoSize();
            }
            catch (Exception e)
            {
                Logger.OutputLog("XlsDef", e, "Excel Report Writing");
                throw;
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 3
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                foreach (var item in Items)
                {
                    item.WriteTo(writer, param);
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 4
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. 5
0
        public HSSFWorkbook Build()
        {
            Initialize();

            var writer = new XlsWriter(null, Workbook, Sheet, 0, 0);

            Def.WriteTo(writer);

/*
 *          foreach (var area in Def.Areas)
 *          {
 *              using (var areaWriter = writer.AddArea())
 *              {
 *                  BuildArea(area, areaWriter);
 *              }
 *          }
 */
            return(Workbook);
        }
Esempio n. 6
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. 7
0
        public XlsWriter(XlsWriter parent, HSSFWorkbook workbook, Sheet sheet, int startRow, int startCol)
        {
            Parent          = parent;
            Workbook        = workbook;
            Sheet           = sheet;
            StartRowIndex   = startRow;
            StartColIndex   = startCol;
            CurrentRowIndex = startRow;
            CurrentColIndex = startCol;
            NextRowIndex    = startRow;
            NextColIndex    = startCol;

            if (Parent != null)
            {
//                BorderTop = Parent.BorderTop;
//                BorderLeft = Parent.BorderLeft;
//                BorderRight = Parent.BorderRight;
//                BorderBottom = Parent.BorderBottom;
                Style = Parent.Style;

                EndRowIndex = Math.Max(Parent.EndRowIndex, CurrentRowIndex);
                EndColIndex = Math.Max(Parent.EndColIndex, CurrentColIndex);
            }
        }
Esempio n. 8
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. 9
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;
            }
        }
Esempio n. 10
0
        public override void WriteTo(XlsWriter writer, int param = 0)
        {
            var oldStyle = writer.MergeStyle(Style);

            try
            {
                var i = 0;
                while (!RowDatas.Eof())
                {
                    using (var rowWriter = writer.AddRowArea(GetRows(), GetCols()))
                    {
                        // rowWriter.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);
                        foreach (var item in Items)
                        {
                            if (item.GetRows() == 0)
                            {
                                continue;
                            }

                            using (var colWriter = rowWriter.AddColArea())
                            {
                                item.WriteTo(colWriter, param);
                            }
                        }
                    }
                    RowDatas.Next();
                    i++;
                }
                if (i == 0)
                {
                    using (var rowWriter = writer.AddRowArea(GetRows(), GetCols()))
                    {
                        using (var colWriter = rowWriter.AddColArea())
                        {
                            var noRecord = new XlsText("Нет данных", Items != null && Items.Count > 0 ? Items[Items.Count - 1].GetCols() : 1)
                            {
                                Style = { FontColor = IndexedColors.GREY_50_PERCENT.Index, HAlign = HAlignment.Center }
                            };
                            noRecord.WriteTo(colWriter, param);
                        }
                    }
                }
                else if (ShowSummary)
                {
                    using (var rowWriter = writer.AddRowArea(GetRows(), GetCols()))
                    {
                        rowWriter.Style.FontStyle |= FontStyle.Bold;
                        // rowWriter.SetBorder(BorderTop, BorderLeft, BorderRight, BorderBottom);
                        foreach (var item in Items)
                        {
                            if (item.GetRows() == 0)
                            {
                                continue;
                            }

                            using (var colWriter = rowWriter.AddColArea())
                            {
                                item.WriteTo(colWriter, WriteSummaryRow);
                            }
                        }
                    }
                }
            }
            finally
            {
                writer.Style = oldStyle;
            }
        }
Esempio n. 11
0
 public XlsWriter(XlsWriter parent, HSSFWorkbook workbook, Sheet sheet, int startRow, int startCol, int endRow, int endCol) :
     this(parent, workbook, sheet, startRow, startCol)
 {
     EndRowIndex = Math.Max(endRow, CurrentRowIndex);
     EndColIndex = Math.Max(endCol, CurrentColIndex);
 }
Esempio n. 12
0
 public virtual void WriteTo(XlsWriter writer, int param = 0)
 {
 }