当前位置: 首页>>代码示例>>C#>>正文


C# DocumentBuilder.InsertField方法代码示例

本文整理汇总了C#中DocumentBuilder.InsertField方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder.InsertField方法的具体用法?C# DocumentBuilder.InsertField怎么用?C# DocumentBuilder.InsertField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentBuilder的用法示例。


在下文中一共展示了DocumentBuilder.InsertField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateDocumentFillWithDummyText

        /// <summary>
        /// Create new document with text
        /// </summary>
        internal static Document CreateDocumentFillWithDummyText()
        {
            Document doc = new Document();

            //Remove the previous changes of the document
            doc.RemoveAllChildren();

            //Set the document author
            doc.BuiltInDocumentProperties.Author = "Test Author";

            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.Write("Page ");
            builder.InsertField("PAGE", "");
            builder.Write(" of ");
            builder.InsertField("NUMPAGES", "");

            //Insert new table with two rows and two cells
            InsertTable(builder);

            builder.Writeln("Hello World!");

            // Continued on page 2 of the document content
            builder.InsertBreak(BreakType.PageBreak);

            //Insert TOC entries
            InsertToc(builder);

            return doc;
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:33,代码来源:DocumentHelper.cs

示例2: Run

        public static void Run()
        {
            // ExStart:ChangeFieldUpdateCultureSource
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();
            // We will test this functionality creating a document with two fields with date formatting
            // ExStart:DocumentBuilderInsertField
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert content with German locale.
            builder.Font.LocaleId = 1031;
            builder.InsertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
            builder.Write(" - ");
            builder.InsertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");
            // ExEnd:DocumentBuilderInsertField
            // Shows how to specify where the culture used for date formatting during field update and mail merge is chosen from.
            // Set the culture used during field update to the culture used by the field.            
            doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
            doc.MailMerge.Execute(new string[] { "Date2" }, new object[] { new DateTime(2011, 1, 01) });
            dataDir = dataDir + "Field.ChangeFieldUpdateCultureSource_out.doc";
            doc.Save(dataDir);
            // ExEnd:ChangeFieldUpdateCultureSource

            Console.WriteLine("\nCulture changed successfully used in formatting fields during update.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:ChangeFieldUpdateCultureSource.cs

示例3: Run

        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();

            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a few page breaks (just for testing)
            for (int i = 0; i < 5; i++)
                builder.InsertBreak(BreakType.PageBreak);

            // Move the DocumentBuilder cursor into the primary footer.
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

            // We want to insert a field like this:
            // { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
            Field field = builder.InsertField(@"IF ");
            builder.MoveTo(field.Separator);
            builder.InsertField("PAGE");
            builder.Write(" <> ");
            builder.InsertField("NUMPAGES");
            builder.Write(" \"See Next Page\" \"Last Page\" ");

            // Finally update the outer field to recalcaluate the final value. Doing this will automatically update
            // the inner fields at the same time.
            field.Update();

            doc.Save(dataDir + "InsertNestedFields Out.docx");

            Console.WriteLine("\nInserted nested fields in the document successfully.\nFile saved at " + dataDir + "InsertNestedFields Out.docx");
        }
开发者ID:robv8r,项目名称:Aspose_Words_NET,代码行数:32,代码来源:InsertNestedFields.cs

示例4: Main

        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //ExStart
            //ExFor:DocumentBuilder.InsertField(string)
            //ExId:DocumentBuilderInsertNestedFields
            //ExSummary:Demonstrates how to insert fields nested within another field using DocumentBuilder.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a few page breaks (just for testing)
            for (int i = 0; i < 5; i++)
                builder.InsertBreak(BreakType.PageBreak);

            // Move the DocumentBuilder cursor into the primary footer.
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

            // We want to insert a field like this:
            // { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
            Field field = builder.InsertField(@"IF ");
            builder.MoveTo(field.Separator);
            builder.InsertField("PAGE");
            builder.Write(" <> ");
            builder.InsertField("NUMPAGES");
            builder.Write(" \"See Next Page\" \"Last Page\" ");

            // Finally update the outer field to recalcaluate the final value. Doing this will automatically update
            // the inner fields at the same time.
            field.Update();

            doc.Save(dataDir + "InsertNestedFields Out.docx");
            //ExEnd
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:35,代码来源:Program.cs

示例5: EnsureQuoteField

        /// <summary>
        /// Ensure that the quote field is present at the start of the given document.
        /// </summary>
        public static void EnsureQuoteField(Document document)
        {
            var container = GetReferenceFieldContainer(document);
            if (container == null)
                throw new Exception("Unable to place quote reference field: no paragraph could be found.");

            // If the first field in the document is "SET q", then exit early
            var firstField = container.FirstChild as FieldStart;
            if (firstField != null && IsQuoteField(firstField))
                return;

            // Otherwise, insert "SET q"
            var builder = new DocumentBuilder(document);
            if (container.FirstChild != null)
            {
                // Insert the new field at the beginning of the first paragraph
                var field = builder.InsertField(" SET q \"\\\"\" ");
                var insertBefore = container.FirstChild;
                foreach (var node in field.Start.GetSelfAndFollowingSiblings().TakeUpToNode(field.End).Reverse().ToArray())
                {
                    container.InsertBefore(node, insertBefore);
                    insertBefore = node;
                }
            }
            else
            {
                // The paragraph is empty, so just insert the field
                builder.MoveToParagraph(0, 0);
                builder.InsertField(" SET q \"\\\"\" ");
            }
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:34,代码来源:QuoteCharacters.cs

示例6: Main

        static void Main(string[] args)
        {
            // Check for license and apply if exists
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
            if (File.Exists(licenseFile))
            {
                // Apply Aspose.Words API License
                Aspose.Words.License license = new Aspose.Words.License();
                // Place license file in Bin/Debug/ Folder
                license.SetLicense("Aspose.Words.lic");
            }

            Document doc = new Document("../../data/document.doc");

            // Enter a dummy field into the document.
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertField("MERGEFIELD Field");

            // GetText will retrieve all field codes and special characters
            Console.WriteLine("GetText() Result: " + doc.GetText());

            string text = doc.GetText();
            text = text.Replace(ControlChar.Cr, ControlChar.CrLf);

            Console.WriteLine("Replaced text Result: " + text);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:Program.cs

示例7: Run

        public static void Run()
        {
            // ExStart:ChangeLocale
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();

            // Create a blank document.
            Document doc = new Document();
            DocumentBuilder b = new DocumentBuilder(doc);
            b.InsertField("MERGEFIELD Date");

            // Store the current culture so it can be set back once mail merge is complete.
            CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
            // Set to German language so dates and numbers are formatted using this culture during mail merge.
            Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

            // Execute mail merge.
            doc.MailMerge.Execute(new string[] { "Date" }, new object[] { DateTime.Now });

            // Restore the original culture.
            Thread.CurrentThread.CurrentCulture = currentCulture;
            doc.Save(dataDir + "Field.ChangeLocale_out.doc");
            // ExEnd:ChangeLocale

            Console.WriteLine("\nCulture changed successfully used in formatting fields during update.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:ChangeLocale.cs

示例8: TryParse_NonMergeField_ReturnsFalse

        public void TryParse_NonMergeField_ReturnsFalse()
        {
            var builder = new DocumentBuilder();
            var field = builder.InsertField(" IF \"True\"=\"True\" \"Yes\" \"No\" ");
            var fieldStart = field.Start;

            MergeField mergeField;
            Assert.IsFalse(MergeField.TryParse(fieldStart, out mergeField), "Should not be able to parse an IF field as a merge field.");
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:9,代码来源:MergeFieldTests.cs

示例9: MergeDocText_HyperlinkQueryString

        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>
                ");
        }
开发者ID:vc3,项目名称:ExoMerge,代码行数:56,代码来源:NodeTextMergeTests.cs

示例10: InsertBarcodeIntoFooter

        // ExStart:InsertBarcodeIntoFooter
        private static void InsertBarcodeIntoFooter(DocumentBuilder builder, Section section, int pageId, HeaderFooterType footerType)
        {
            // Move to the footer type in the specific section.
            builder.MoveToSection(section.Document.IndexOf(section));
            builder.MoveToHeaderFooter(footerType);

            // Insert the barcode, then move to the next line and insert the ID along with the page number.
            // Use pageId if you need to insert a different barcode on each page. 0 = First page, 1 = Second page etc.    
            builder.InsertImage(System.Drawing.Image.FromFile( RunExamples.GetDataDir_WorkingWithImages() + "Barcode1.png"));
            builder.Writeln();
            builder.Write("1234567890");
            builder.InsertField("PAGE");

            // Create a right aligned tab at the right margin.
            double tabPos = section.PageSetup.PageWidth - section.PageSetup.RightMargin - section.PageSetup.LeftMargin;
            builder.CurrentParagraph.ParagraphFormat.TabStops.Add(new TabStop(tabPos, TabAlignment.Right, TabLeader.None));

            // Move to the right hand side of the page and insert the page and page total.
            builder.Write(ControlChar.Tab);
            builder.InsertField("PAGE");
            builder.Write(" of ");
            builder.InsertField("NUMPAGES");
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:24,代码来源:InsertBarcodeImage.cs

示例11: Run

        public static void Run()
        {
            // ExStart:InsertField
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();

            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertField(@"MERGEFIELD MyFieldName \* MERGEFORMAT");
            dataDir = dataDir + "InsertField_out.docx";
            doc.Save(dataDir);
            // ExEnd:InsertField
            Console.WriteLine("\nInserted field in the document successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:14,代码来源:InsertField.cs

示例12: Main

        static void Main(string[] args)
        {
            string mypath = "";
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            // Create the headers.
            builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
            builder.Write("Header Text goes here...");
            //add footer having current date
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
            builder.InsertField("Date", "");

            doc.UpdateFields();
            doc.Save(mypath + "Insert Headers and Footers.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:15,代码来源:Program.cs

示例13: Main

        static void Main(string[] args)
        {
            Document doc = new Document("../../data/document.doc");

            // Enter a dummy field into the document.
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertField("MERGEFIELD Field");

            // GetText will retrieve all field codes and special characters
            Console.WriteLine("GetText() Result: " + doc.GetText());

            string text = doc.GetText();
            text = text.Replace(ControlChar.Cr, ControlChar.CrLf);

            Console.WriteLine("Replaced text Result: " + text);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:16,代码来源:Program.cs

示例14: Run

        public static void Run()
        {
            // ExStart:ExtractTextOnly
            Document doc = new Document();

            // Enter a dummy field into the document.
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertField("MERGEFIELD Field");

            // GetText will retrieve all field codes and special characters
            Console.WriteLine("GetText() Result: " + doc.GetText());

            // ToString will export the node to the specified format. When converted to text it will not retrieve fields code 
            // Or special characters, but will still contain some natural formatting characters such as paragraph markers etc. 
            // This is the same as "viewing" the document as if it was opened in a text editor.
            Console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text));
            // ExEnd:ExtractTextOnly            
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:18,代码来源:ExtractTextOnly.cs

示例15: Run

        public static void Run()
        {
            // ExStart:InsertMergeFieldUsingDOM
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();
            Document doc = new Document(dataDir + "in.doc");
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Get paragraph you want to append this merge field to
            Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

            // Move cursor to this paragraph
            builder.MoveTo(para);

            // We want to insert a merge field like this:
            // { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" }

            // Create instance of FieldMergeField class and lets build the above field code
            FieldMergeField field = (FieldMergeField)builder.InsertField(FieldType.FieldMergeField, false);

            // { " MERGEFIELD Test1" }
            field.FieldName = "Test1";

            // { " MERGEFIELD Test1 \\b Test2" }
            field.TextBefore = "Test2";

            // { " MERGEFIELD Test1 \\b Test2 \\f Test3 }
            field.TextAfter = "Test3";

            // { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m" }
            field.IsMapped = true;

            // { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" }
            field.IsVerticalFormatting = true;

            // Finally update this merge field
            field.Update();

            dataDir = dataDir + "InsertMergeFieldUsingDOM_out.doc";
            doc.Save(dataDir);
            
            // ExEnd:InsertMergeFieldUsingDOM
            Console.WriteLine("\nMerge field using DOM inserted successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:44,代码来源:InsertMergeFieldUsingDOM.cs


注:本文中的DocumentBuilder.InsertField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。