menu

Xamarin.Forms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class Extensions - Xamarin.Forms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class Extensions

    Implemented alternative method to perform autofit for table

    Inheritance
    System.Object
    Extensions
    Namespace: Syncfusion.DocIORenderer
    Assembly: Syncfusion.DocIORenderer.Portable.dll
    Syntax
    public static class Extensions : Object

    Methods

    AutoFit(IWTable, AutoFitType)

    Resizes the table based on the specified AutoFitType.

    Declaration
    public static void AutoFit(this IWTable table, AutoFitType autoFitType)
    Parameters
    Type Name Description
    IWTable table
    AutoFitType autoFitType

    The AutoFitType member that specifies the type of auto fit layout of table.

    Remarks

    DocIO can resize the table based on the content of the table cells or the width of the document window. You can also use this method to turn off AutoFit so that the table size is fixed, regardless of cell contents or window width. Setting the AutoFit behavior to FitToContent or FitToWindow sets the IsAutoResized property to True if it's currently False. Likewise, setting the AutoFit behavior to FixedColumnWidth sets the IsAutoResized property to False if it's currently True.

    Examples

    The following example illustrates how to append html text to the paragraph.

    //Loads the template document
    WordDocument document = new WordDocument("Sample.docx");
    //Accesses the instance of the first section in the Word document 
    WSection section = document.Sections[0];
    //Accesses the instance of the first table in the section 
    IWTable table = section.Tables[0];
    //Auto fits the table with respect to window.
    table.AutoFit(AutoFitType.FitToWindow);
    //Saves and closes the document instance
    document.Save("TableAutoFit.docx");
    document.Close();
    Private Sub SurroundingSub()
    Dim document As WordDocument = New WordDocument("Sample.docx")
    Dim section As WSection = document.Sections(0)
    Dim table As IWTable = section.Tables(0)
    table.AutoFit(AutoFitType.FitToWindow)
    document.Save("TableAutoFit.docx")
    document.Close()
    End Sub

    AutoFit(WTable, AutoFitType)

    Resizes the table based on the specified AutoFitType.

    Declaration
    public static void AutoFit(this WTable table, AutoFitType autoFitType)
    Parameters
    Type Name Description
    WTable table
    AutoFitType autoFitType

    The AutoFitType member that specifies the type of auto fit layout of table.

    Remarks

    DocIO can resize the table based on the content of the table cells or the width of the document window. You can also use this method to turn off AutoFit so that the table size is fixed, regardless of cell contents or window width. Setting the AutoFit behavior to FitToContent or FitToWindow sets the IsAutoResized property to True if it's currently False. Likewise, setting the AutoFit behavior to FixedColumnWidth sets the IsAutoResized property to False if it's currently True.

    Examples

    The following example illustrates how to append html text to the paragraph.

    //Loads the template document
    WordDocument document = new WordDocument("Sample.docx");
    //Accesses the instance of the first section in the Word document 
    WSection section = document.Sections[0];
    //Accesses the instance of the first table in the section 
    WTable table = section.Tables[0] as WTable;
    //Auto fits the table with respect to window.
    table.AutoFit(AutoFitType.FitToWindow);
    //Saves and closes the document instance
    document.Save("TableAutoFit.docx");
    document.Close();
    Private Sub SurroundingSub()
    Dim document As WordDocument = New WordDocument("Sample.docx")
    Dim section As WSection = document.Sections(0)
    Dim table As WTable = TryCast(section.Tables(0), WTable)
    table.AutoFit(AutoFitType.FitToWindow)
    document.Save("TableAutoFit.docx")
    document.Close()
    End Sub

    SaveAsImage(WChart)

    Save the chart as image.

    Declaration
    public static Stream SaveAsImage(this WChart chart)
    Parameters
    Type Name Description
    WChart chart
    Returns
    Type Description
    System.IO.Stream

    An System.IO.Stream that represent specified chart as image.

    Examples
    //Open the file as Stream.
    using (FileStream docStream = new FileStream("Template.docx", FileMode.Open))
    {
         //Load file stream into Word document.
         using (WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic))
         {
             //Get the first paragraph from the section. 
             WParagraph paragraph = wordDocument.LastSection.Paragraphs[0];
             //Get the chart element from the paragraph.
             WChart chart = paragraph.ChildEntities[0] as WChart;
             //Create an instance of DocIORenderer.
             using (DocIORenderer renderer = new DocIORenderer())
             {
                //Convert chart to an image.
                using (Stream stream = chart.SaveAsImage())
                {
                    //Create the output image file stream. 
                    using (FileStream fileStreamOutput = File.Create("ChartToImage.jpeg"))
                    {
                        //Copies the converted image stream into created output stream.
                        stream.CopyTo(fileStreamOutput);
                    }
                }
             }
         }
    }

    UpdateDocumentFields(IWordDocument, Boolean)

    Updates fields present in the document.

    Declaration
    public static void UpdateDocumentFields(this IWordDocument document, bool performLayout)
    Parameters
    Type Name Description
    IWordDocument document
    System.Boolean performLayout

    Set to true to update the Page, NumPage and PageRef fields in the Word document using Word to PDF layouting engine; otherwise, false.

    Remarks

    Updating of NUMPAGES field and Cross Reference field with Page number and Paragraph number options are not supported in Silverlight, WinRT, Universal and Windows Phone platforms.

    Currently group shapes, drawing canvas, and table auto resizing are not supported in Word to PDF lay outing, and this may lead to update incorrect page number and total number of pages.

    While updating NUMPAGES field and Cross Reference field with Page number and Paragraph number options uses makes use of our Word to PDF layouting engine which may lead to take some considerable amount of performance to update the above mentioned fields.

    Examples

    The following code example demonstrates how to update the fields present in Word document.

      //Load an existing Word document into DocIO instance 
      IWordDocument document = new WordDocument("Input.docx", FormatType.Docx);
      //Updates the fields present in a document.
      document.UpdateDocumentFields(true);
      document.Save("Result.docx", FormatType.Docx);
      document.Close();
      'Load an existing Word document into DocIO instance 
      Dim document As IWordDocument = New WordDocument("Input.docx", FormatType.Docx)
      'Updates the fields present in a document.
      document.UpdateDocumentFields(True)
      document.Save("Result.docx", FormatType.Docx)
      document.Close()

    UpdateDocumentFields(WordDocument, Boolean)

    Updates fields present in the Word document.

    Declaration
    public static void UpdateDocumentFields(this WordDocument document, bool performLayout)
    Parameters
    Type Name Description
    WordDocument document
    System.Boolean performLayout

    Set to true to update the Page, NumPage and PageRef fields in the Word document using Word to PDF layouting engine; otherwise, false.

    Remarks

    Updating of NUMPAGES field and Cross Reference field with Page number and Paragraph number options are not supported in Silverlight, WinRT, Universal and Windows Phone platforms.

    Currently group shapes, drawing canvas, and table auto resizing are not supported in Word to PDF lay outing, and this may lead to update incorrect page number and total number of pages.

    While updating NUMPAGES field and Cross Reference field with Page number and Paragraph number options uses makes use of our Word to PDF layouting engine which may lead to take some considerable amount of performance to update the above mentioned fields.

    Examples

    The following code example demonstrates how to update the fields present in Word document.

      //Load an existing Word document into DocIO instance 
      WordDocument document = new WordDocument("Input.docx", FormatType.Docx);
      //Updates the fields present in a document.
      document.UpdateDocumentFields(true);
      document.Save("Result.docx", FormatType.Docx);
      document.Close();
      'Load an existing Word document into DocIO instance 
      Dim document As New WordDocument("Input.docx", FormatType.Docx)
      'Updates the fields present in a document.
      document.UpdateDocumentFields(True)
      document.Save("Result.docx", FormatType.Docx)
      document.Close()

    UpdateTableOfContents(IWordDocument)

    Update Table of contents in the document.

    Declaration
    public static void UpdateTableOfContents(this IWordDocument document)
    Parameters
    Type Name Description
    IWordDocument document
    Remarks

    Updating TOC makes use of our Word to PDF layouting engine which may lead to the updation of incorrect page number due to its limitations. Also use of WOrd to PDF layout engine may lead to take some considerable amount of performance to update the page numbers.

    Examples

    The following code example demonstrates how to update a TOC in an existing word document.

      //Open an input word template
      IWordDocument document = new WordDocument(@"Template.docx");
      //Update the table of contents.
      document.UpdateTableOfContents();
      //Save and close the Word document instance.
      document.Save("Sample.docx", FormatType.Docx);
      document.Close();
      'Open an input word template
      Dim document As IWordDocument = New WordDocument("Template.docx")
      'Update the table of contents.
      document.UpdateTableOfContents()
      'Save and close the Word document instance.
      document.Save("Sample.docx", FormatType.Docx)
      document.Close()

    UpdateTableOfContents(WordDocument)

    Update Table of contents in the document.

    Declaration
    public static void UpdateTableOfContents(this WordDocument document)
    Parameters
    Type Name Description
    WordDocument document
    Remarks

    Updating TOC makes use of our Word to PDF layouting engine which may lead to the updation of incorrect page number due to its limitations. Also use of WOrd to PDF layout engine may lead to take some considerable amount of performance to update the page numbers.

    Examples

    The following code example demonstrates how to update a TOC in an existing word document.

      //Open an input word template
      WordDocument document = new WordDocument(@"Template.docx");
      //Update the table of contents.
      document.UpdateTableOfContents();
      //Save and close the Word document instance.
      document.Save("Sample.docx", FormatType.Docx);
      document.Close();
      'Open an input word template
      Dim document As New WordDocument("Template.docx")
      'Update the table of contents.
      document.UpdateTableOfContents()
      'Save and close the Word document instance.
      document.Save("Sample.docx", FormatType.Docx)
      document.Close()

    UpdateWordCount(IWordDocument, Boolean)

    Updates Paragraphs count, Word count and Character count. Updates page count if performLayout set to true using Word to PDF layout engine.

    Declaration
    public static void UpdateWordCount(this IWordDocument document, bool performlayout)
    Parameters
    Type Name Description
    IWordDocument document
    System.Boolean performlayout
    Examples

    The following code example demonstrates how to update Page count, Paragraphs count, Word count and Character count in the document.

        //Open an input word template from stream through constructor of `WordDocument` class
        FileStream inputStream = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read);
        IWordDocument document = new WordDocument(inputStream, FormatType.Automatic);
        //Update the Page count, Paragraphs count, Word count and Character count in the document
        document.UpdateWordCount(true);
        FileStream outputStream = new FileStream(@"Sample.docx", FileMode.Create);
        //Save and close the Word document instance.
        document.Save(outputStream, FormatType.Docx);
        document.Close();
        'Open an input word template
        Dim inputStream As FileStream = New FileStream("Template.docx", FileMode.Open, FileAccess.Read)
        Dim document As IWordDocument = New WordDocument(inputStream, FormatType.Automatic)
        'Update the Page count, Paragraphs count, Word count and Character count in the document.
        document.UpdateWordCount(True)
        Dim outputStream As FileStream = New FileStream("Sample.docx", FileMode.Create)
        'Save and close the Word document instance.
        document.Save(outputStream, FormatType.Docx)
        document.Close()

    UpdateWordCount(WordDocument, Boolean)

    Updates Paragraphs count, Word count and Character count. Updates page count if performLayout set to true using Word to PDF layout engine.

    Declaration
    public static void UpdateWordCount(this WordDocument document, bool performlayout)
    Parameters
    Type Name Description
    WordDocument document
    System.Boolean performlayout
    Examples

    The following code example demonstrates how to update Page count, Paragraphs count, Word count and Character count in the document.

        //Open an input word template from stream through constructor of `WordDocument` class
        FileStream inputStream = new FileStream(@"Template.docx", FileMode.Open, FileAccess.Read);
        WordDocument document = new WordDocument(inputStream, FormatType.Automatic);
        //Update the Page count, Paragraphs count, Word count and Character count in the document
        document.UpdateWordCount(true);
        FileStream outputStream = new FileStream(@"Sample.docx", FileMode.Create);
        //Save and close the Word document instance.
        document.Save(outputStream, FormatType.Docx);
        document.Close();
        'Open an input word template
        Dim inputStream As FileStream = New FileStream("Template.docx", FileMode.Open, FileAccess.Read)
        Dim document As WordDocument = New WordDocument(inputStream, FormatType.Automatic)
        'Update the Page count, Paragraphs count, Word count and Character count in the document.
        document.UpdateWordCount(True)
        Dim outputStream As FileStream = New FileStream("Sample.docx", FileMode.Create)
        'Save and close the Word document instance.
        document.Save(outputStream, FormatType.Docx)
        document.Close()
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved