Пример #1
0
        private void BuildRow(XlsItem item, DocX document)
        {
            var row      = (XlsRow)item;
            var oldStyle = MergeStyle(item.Style);

            try
            {
                var formatting = GetFormatting();
                if (/*row.Items.Count < 2 &&*/ !row.Items.Exists(i => (i is XlsGroup)))
                {
                    var para = AppendParagraph(document);
                    foreach (var child in row.Items)
                    {
                        AppendParaText(child, para);
                    }
                }
                else
                {
                    var table = document.InsertTable(row.GetRows(), row.GetCols());
                }
            }
            finally
            {
                SetStyle(oldStyle);
            }
        }
Пример #2
0
 private void AppendParaText(XlsItem item, Paragraph para)
 {
     if (item is XlsCell)
     {
         var value = ((XlsCell)item).GetValue();
         para.Append(value != null ? value.ToString() : String.Empty);
     }
 }
        private void BuildItem(XlsItem item, WordDocDef wordDef)
        {
            var row = item as XlsRow;

            if (row != null)
            {
                if (row.Items.Count == 0)
                {
                    return;
                }

                if (row.Items.Count == 1 && row.Items[0] is XlsCell)
                {
                    var cell = (XlsCell)row.Items[0];
                    var val  = cell.GetValue();
                    wordDef.AddParagraph(val != null ? val.ToString() : String.Empty, cell.Style);
                    return;
                }

                /*var tableBuilder = new TableBuilder(row.GetRows(), row.GetCols());
                 * RowToTableInfo(row, tableBuilder, 0, 0);*/

                var table = wordDef.AddTable();
                table.Style = row.Style;
                BuildTable(row, table, 0, 0);
                return;
            }
            var grid = item as XlsGrid;

            if (grid != null)
            {
                if (grid.Items.Count == 0)
                {
                    return;
                }

                //var tableBuilder = new TableBuilder(grid.GetRows(), grid.GetCols());
                var rowNo = 0;
                var table = wordDef.AddTable();
                table.Style = grid.Style;
                while (!grid.RowDatas.Eof())
                {
                    foreach (var gridRow in grid.Items.OfType <XlsRow>())
                    {
                        BuildTable(gridRow, table, rowNo, 0);
                    }
                    grid.RowDatas.Next();
                    rowNo++;
                }
                wordDef.AddParagraph(String.Empty);
                return;
            }
            var area = item as XlsArea;

            if (area != null)
            {
                foreach (var subItem in area.Items)
                {
                    BuildItem(subItem, wordDef);
                }
            }
        }
        private void AddTableRowCell(WordTableDef table, WordTableRowDef row, XlsItem item, ref int rowNo, ref int colNo)
        {
            var field = item as XlsDataField;

            if (field != null)
            {
                var cell = row.AddCell(colNo);
                cell.Style   = field.Style;
                cell.ColSpan = 1;
                var val  = ((XlsCell)item).GetValue();
                var type = field.Field.GetDataType();
                var s    = String.Empty;
                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;
                    }
                }
                cell.AddText(s, field.Style);
                colNo++;
            }
            else
            {
                var xlsCell = item as XlsCell;
                if (xlsCell != null)
                {
                    var cell = row.AddCell(colNo);
                    cell.Style   = xlsCell.Style;
                    cell.ColSpan = 1;
                    var val = xlsCell.GetValue();
                    cell.AddText(val != null ? val.ToString() : String.Empty, xlsCell.Style);
                    colNo++;
                }
                else
                {
                    var xlsNode = item as XlsNode;
                    if (xlsNode != null)
                    {
                        var cell = row.AddCell(colNo);
                        cell.Style   = xlsNode.Style;
                        cell.ColSpan = item.GetCols();
                        var textNode = item as XlsTextNode;
                        if (textNode != null)
                        {
                            cell.AddText(textNode.Text, xlsNode.Style);
                        }
                        else
                        {
                            var cellNode = item as XlsCellNode;
                            if (cellNode != null)
                            {
                                var val = cellNode.Cell.GetValue();
                                cell.AddText(val != null ? val.ToString() : String.Empty, xlsNode.Style);
                            }
                        }

                        var node = xlsNode;
                        if (node.Items.Count > 0)
                        {
                            AddNodeCell(node, table, rowNo + 1, colNo);
                        }
                        colNo += node.GetCols();
                    }
                }
            }
        }
Пример #5
0
        private void BuildItem(XlsItem item, DocX document)
        {
            var method = (from m in _methods where m.Key == item.GetType() select m.Value).First();

            method(item, document);
        }
Пример #6
0
 private void BuildGrid(XlsItem item, DocX document)
 {
     throw new NotImplementedException();
 }
Пример #7
0
 private void BuildArea(XlsItem arg1, DocX arg2)
 {
     BuildArea((XlsArea)arg1, arg2);
 }