コード例 #1
0
ファイル: NodeTextMergeTests.cs プロジェクト: vc3/ExoMerge
        public void MergeDocText_HyperlinkQueryString()
        {
            var doc = new Document();

            var builder = new DocumentBuilder(doc);

            builder.InsertRun("^ ");

            builder.InsertField("HYPERLINK \"https://google.com/q=%7b%7bQuery%7d%7d\"");

            builder.InsertRun(" $");

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph>
                        <Run>^ </Run>
                        <FieldStart></FieldStart>
                        <Run>HYPERLINK ""https://google.com/q=%7b%7bQuery%7d%7d""</Run>
                        <FieldSeparator></FieldSeparator>
                        <FieldEnd></FieldEnd>
                        <Run> $</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>
                ");

            var data = new
            {
                Query = "Arnold Schwarzenegger",
            };

            doc.Merge(data);

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph>
                        <Run>^ </Run>
                        <FieldStart></FieldStart>
                        <Run>HYPERLINK ""</Run>
                        <Run>https://google.com/q=</Run>
                        <Run>Arnold%20Schwarzenegger</Run>
                        <Run>""</Run>
                        <FieldSeparator></FieldSeparator>
                        <FieldEnd></FieldEnd>
                        <Run> $</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>
                ");
        }
コード例 #2
0
ファイル: DocumentConverter.cs プロジェクト: vc3/ExoMerge
        public static Document FromStrings(string[] strings, out Run[] runs)
        {
            var builder = new DocumentBuilder();

            var runList = new List<Run>();

            var comments = new Dictionary<string, Comment>();

            foreach (var str in strings)
            {
                // Bookmark
                if (str.StartsWith("@{") && str.EndsWith("}"))
                {
                    if (str.StartsWith("@{/"))
                    {
                        var bookmarkName = str.Substring(3, str.Length - 4);
                        builder.EndBookmark(bookmarkName);
                    }
                    else
                    {
                        var bookmarkName = str.Substring(2, str.Length - 3);
                        builder.StartBookmark(bookmarkName);
                    }

                    continue;
                }

                // Comment
                if (str.StartsWith("!{") && str.EndsWith("}"))
                {
                    if (str.StartsWith("!{/"))
                    {
                        var commentName = str.Substring(3, str.Length - 4);

                        var comment = comments[commentName];

                        var commentEnd = new CommentRangeEnd(builder.Document, comment.Id);

                        builder.InsertNode(commentEnd);
                    }
                    else
                    {
                        var commentName = str.Substring(2, str.Length - 3);

                        var comment = new Comment(builder.Document, "", "", DateTime.Now);

                        comments.Add(commentName, comment);

                        comment.SetText("Comment: " + commentName);

                        builder.InsertNode(comment);

                        var commentStart = new CommentRangeStart(builder.Document, comment.Id);

                        builder.InsertNode(commentStart);
                    }

                    continue;
                }

                runList.Add(builder.InsertRun(str));
            }

            runs = runList.ToArray();

            return builder.Document;
        }
コード例 #3
0
ファイル: NodeTextMergeTests.cs プロジェクト: vc3/ExoMerge
        public void MergeDocText_HyperlinkUrl()
        {
            var doc = new Document();

            var builder = new DocumentBuilder(doc);

            builder.InsertRun("^ ");

            builder.InsertField("HYPERLINK \"%7b%7bUrl%7d%7d\"");

            builder.InsertRun(" $");

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph>
                        <Run>^ </Run>
                        <FieldStart></FieldStart>
                        <Run>HYPERLINK ""%7b%7bUrl%7d%7d""</Run>
                        <FieldSeparator></FieldSeparator>
                        <FieldEnd></FieldEnd>
                        <Run> $</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>
                ");

            var data = new
            {
                Url = "https://www.google.com",
            };

            doc.Merge(data);

            doc.AssertXml(@"
                <Document>
                  <Section>
                    <Body>
                      <Paragraph>
                        <Run>^ </Run>
                        <FieldStart></FieldStart>
                        <Run>HYPERLINK ""</Run>
                        <Run>https://www.google.com</Run>
                        <Run>""</Run>
                        <FieldSeparator></FieldSeparator>
                        <FieldEnd></FieldEnd>
                        <Run> $</Run>
                      </Paragraph>
                    </Body>
                  </Section>
                </Document>
                ");
        }