Ejemplo n.º 1
0
        void AddRow(XmlNode src, RowKind kind, Int32 rowNo)
        {
            ExRow row       = _sheet.GetRow(rowNo, kind);
            var   classAttr = src.Attributes["class"];

            if (classAttr != null)
            {
                row.SetRoleAndStyle(classAttr.Value);
            }
            var heightAttr = src.Attributes["data-row-height"];

            if (heightAttr != null)
            {
                if (UInt32.TryParse(heightAttr.Value, out UInt32 height))
                {
                    row.Height = height;
                }
            }
            foreach (var cn in src.ChildNodes.OfType <XmlNode>().Where(node => node.Name == "td"))
            {
                var colSpanAttr = cn.Attributes["colspan"];
                var rowSpanAttr = cn.Attributes["rowspan"];
                var span        = new CellSpan();
                if (colSpanAttr != null)
                {
                    span.Col = Int32.Parse(colSpanAttr.Value);
                }
                if (rowSpanAttr != null)
                {
                    span.Row = Int32.Parse(rowSpanAttr.Value);
                }

                var    dataTypeAttr = cn.Attributes["data-type"];
                String dataType     = null;
                if (dataTypeAttr != null)
                {
                    dataType = dataTypeAttr.Value;
                }
                var    cellClassAttr = cn.Attributes["class"];
                String cellClass     = null;
                if (cellClassAttr != null)
                {
                    cellClass = cellClassAttr.Value;
                }

                String cellText = GetNodeText(cn);
                _sheet.AddCell(rowNo, row, span, cellText, dataType, cellClass);
            }
        }
Ejemplo n.º 2
0
        public ExCell AddCell(Int32 rowNo, ExRow exRow, CellSpan span, String value, String dataType, String cellClass)
        {
            // first empty cell
            var row = GetRow(rowNo, exRow.Kind);

            var(cell, index) = row.AddCell();
            cell.Span        = span;
            cell.SetValue(value, dataType);
            cell.StyleIndex = Styles.GetOrCreate(cell.GetStyle(row, cellClass));
            if (span.Col == 0 && span.Row == 0)
            {
                return(cell);
            }
            if (span.Col > 0 && span.Row == 0)
            {
                for (var c = 0; c < span.Col - 1; c++)
                {
                    AddSpanCell(exRow.Kind, rowNo, index + c + 1).StyleIndex = cell.StyleIndex;
                }
            }
            else if (span.Col == 0 && span.Row > 0)
            {
                for (var r = 0; r < span.Row - 1; r++)
                {
                    AddSpanCell(exRow.Kind, rowNo + r + 1, index).StyleIndex = cell.StyleIndex;
                }
            }
            else
            {
                // first row
                for (var c = 0; c < span.Col - 1; c++)
                {
                    AddSpanCell(exRow.Kind, rowNo, index + c + 1).StyleIndex = cell.StyleIndex;
                }
                // next rows
                for (var r = 1; r < span.Row; r++)
                {
                    for (var c = 0; c < span.Col; c++)
                    {
                        AddSpanCell(exRow.Kind, rowNo + r, index + c).StyleIndex = cell.StyleIndex;
                    }
                }
            }
            return(cell);
        }