예제 #1
0
        public void Write(XElement parent)
        {
            XNamespace ns = parent.Name.Namespace;

            XElement cell = new XElement(ns + "tc");

            parent.Add(cell);

            XElement props = new XElement(ns + "tcPr");

            cell.Add(props);

            XElement span = new XElement(
                ns + "gridSpan",
                new XAttribute(ns + "val", _columnSpan));

            props.Add(span);

            XElement margin = StyleHelpers.CreateMargin(ns, "tcMar", _style?.Padding);

            if (margin != null)
            {
                props.Add(margin);
            }

            //	The last child of a cell must be a paragraph. ECMA-376 Part 1, section
            //	17.4.65 on page 457, says that
            //
            //		"a table cell can contain any block-level content, which allows for
            //		the nesting of paragraphs and tables within table cells. If a table
            //		cell does not include at least one block-level element, then this
            //		document shall be considered corrupt."
            //
            //	This doesn't seem to say that the last child must be a paragraph, but if
            //	it's not then Word reports this error:
            //
            //		"Ambiguous cell mapping encountered. Possible missing paragraph
            //		element. <p> elements are required before very </tc>."
            if ((_content.Count == 0) || !(_content[_content.Count - 1] is Paragraph))
            {
//				Paragraph p = new Paragraph(new Report.Style.TextStyle());
//				p.AddRun("hello", new Report.Style.Font { FamilyName="courier new", Size=10, Bold=true}, new Report.Style.Color{Red=1, Green=0,Blue=0});
//				_content.Add(p);
                AddParagraph(new s.TextStyle(), t.TrackingInfo.None);
            }

            foreach (IBlockContent content in _content)
            {
                content.Write(cell);
            }
        }
예제 #2
0
        public void Write(XElement parent)
        {
            XNamespace ns = parent.Name.Namespace;

            XElement table = new XElement(ns + "tbl");

            parent.Add(table);

            XElement props = new XElement(ns + "tblPr");

            table.Add(props);

            XElement algorithm = new XElement(
                ns + "tblLayout",
                new XAttribute(ns + "type", "fixed"));

            props.Add(algorithm);

            XElement width = StyleHelpers.CreateWidth(ns, "tblW", _width);

            props.Add(width);

            XElement grid = new XElement(ns + "tblGrid");

            props.Add(grid);

            foreach (int columnWidth in _columnWidths)
            {
                XElement column = new XElement(
                    ns + "gridCol",
                    new XAttribute(ns + "w", columnWidth));
                grid.Add(column);
            }

            XElement border = StyleHelpers.CreateBorder(ns, "tblBorders", _style?.Border, _style?.Padding);

            if (border != null)
            {
                props.Add(border);
            }

            foreach (TableRow row in _rows)
            {
                row.Write(table);
            }
        }
예제 #3
0
        public void Write(XElement parent)
        {
            XNamespace ns = parent.Name.Namespace;

            XElement abstractNum = new XElement(
                ns + "abstractNum",
                new XAttribute(ns + "abstractNumId", _id));

            parent.Add(abstractNum);

            XElement multi = new XElement(
                ns + "multiLevelType",
                new XAttribute(ns + "val", "multiLevel"));

            abstractNum.Add(multi);

            XElement lvl = new XElement(
                ns + "lvl",
                new XAttribute(ns + "ilvl", _level));

            //	We use level zero to mean "no indent" (that is, not a list
            //	at all) but Word starts numbering levels at zero, so we
            //	subtract one here
            abstractNum.Add(lvl);

            string   formatName = GetNumFmt(_style.NumberStyle);
            XElement numFmt     = new XElement(
                ns + "numFmt",
                new XAttribute(ns + "val", formatName));

            lvl.Add(numFmt);

            XElement lvlText = new XElement(
                ns + "lvlText",
                new XAttribute(ns + "val", _text));

            lvl.Add(lvlText);

            XElement rPr = StyleHelpers.AddRunProperties(lvl, _style.Font, _style.Color);

            //TODO: tabs?
        }
예제 #4
0
        public void Write(XElement paragraph)
        {
            XNamespace ns = paragraph.Name.Namespace;

            XElement run = new XElement(ns + "r");

            paragraph.Add(run);

            //	Style properties in Word can be inherited in the style
            //	hierarchy, but our layouts have already collapsed the
            //	hierarchy into a single description, and so we don't
            //	need worry about inheritance in Word.

            XElement props = StyleHelpers.AddRunProperties(run, _font, _color);

            XElement text = new XElement(
                ns + "t",
                new XAttribute(XNamespace.Xml + "space", "preserve"));

            text.Value = _text;
            run.Add(text);
        }
예제 #5
0
        public void Write(XElement parent)
        {
            XNamespace ns = parent.Name.Namespace;

            XElement para = new XElement(ns + "p");

            parent.Add(para);

            XElement props = new XElement(ns + "pPr");

            para.Add(props);

            if (_numberingId > -1)
            {
                XElement numPr = new XElement(ns + "numPr");
                props.Add(numPr);

                XElement ilvl = new XElement(
                    ns + "ilvl",
                    new XAttribute(ns + "val", _numberingLevel));
                numPr.Add(ilvl);

                XElement numId = new XElement(
                    ns + "numId",
                    new XAttribute(ns + "val", _numberingId));
                numPr.Add(numId);
            }

            string align = null;

            switch (_style.Alignment)
            {
            case s.TextAlignment.Left:    align = "start";  break;

            case s.TextAlignment.Right:   align = "end";    break;

            case s.TextAlignment.Center:  align = "center"; break;

            case s.TextAlignment.Justify: align = "both";   break;
            }
            if (align != null)
            {
                XElement prop = new XElement(
                    ns + "jc",
                    new XAttribute(ns + "val", align));
                props.Add(prop);
            }

            //TODO: keepLines, keepNext, pageBreakBefore

            XElement border = StyleHelpers.CreateBorder(ns, "pBdr", _style.Border, _style.Padding);

            if (border != null)
            {
                props.Add(border);
            }

            if (_style.BackColor != null)
            {
                int    red   = (int)(_style.BackColor.Red * 255f);
                int    green = (int)(_style.BackColor.Green * 255f);
                int    blue  = (int)(_style.BackColor.Blue * 255f);
                string color = $"{red:X2}{green:X2}{blue:X2}";

                XElement shd = new XElement(
                    ns + "shd",
                    new XAttribute(ns + "fill", color));
                props.Add(shd);
            }

            foreach (IParagraphContent content in _content)
            {
                content.Write(para);
            }
        }