We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Retaining Format after New Line in DocIO

I am creating a Word document with DocIO. The resulting file is distributed to various individuals for manual editing. When I create a Word document in MS Word (not DocIO), I can put the cursor at the end of a paragraph and press enter, and the new paragraph retains the formatting of the previous paragraph. When I do the same thing with the DocIO-generated document, the new paragraph reverts to the default formatting. How do I get a DocIO-generated document to behave the same as a Microsoft Word-generated document?

5 Replies

SV Sivasubramani V Syncfusion Team September 15, 2015 06:06 AM UTC

Hi James,

Thank you for using Syncfusion products.

We are unable to reproduce the reported retain formatting issue at our end. Please refer to the following sample which we have used to investigate the issue,

http://www.syncfusion.com/downloads/support/directtrac/140008/ze/Sample7531297   

Please modify the attached sample or update the complete runnable sample to reproduce issue for further analysis on our side.

Please refer to the below UG documentation to know about the complete functionalities on paragraph style and formatting,

http://help.syncfusion.com/windowsforms/docio/working-with-paragraphs

Regards,
Sivasubramani.





SV Sivasubramani V Syncfusion Team September 15, 2015 06:11 AM UTC

Hi James,

Please ignore our previous update..

We are unable to reproduce the reported retain formatting issue at our end. Please refer to the following sample which we have used to investigate the issue,

http://www.syncfusion.com/downloads/support/forum/120251/ze/Sample1123164940

Please modify the attached sample or update the complete runnable sample to reproduce issue for further analysis on our side.

Please refer to the below UG documentation to know about the complete functionalities on paragraph style and formatting,

http://help.syncfusion.com/windowsforms/docio/working-with-paragraphs

Regards,
Sivasubramani.



KK K Kalai Selvi Syncfusion Team September 16, 2015 03:42 AM UTC

From: Brower, James
Sent: Tuesday, September 15, 2015 10:23 AM
To: Syncfusion Support <support@syncfusion.com>
Subject: RE: Syncfusion support community forum 120251, Retaining Format after New Line in DocIO, has been updated.


Thank you for your response. However, I’m not sure how the sample you provided applies to my issue. The test document contains no text, nor does it have any custom styles to demonstrate the reverting back to the default style. Also, though I don’t know if this has any bearing, I am creating the Word document, not using a pre-existing template.

Below is a sample program which creates a simple document with a one-sentence paragraph, to which is applied a custom style. The file is saved in the same folder in which the application is run. If you open this document (it’s in Word 2010 format), place the cursor at the end of the paragraph, and press Enter, the new paragraph will not have the same formatting as the prior paragraph; rather, it has the default formatting. (The paragraph is created with FontName = Tahoma, FontSize = 8, Bold = True and a set of tab stops; the new paragraph reverts to FontName = Times New Roman, FontSize = 12, Bold = False and the default tab stops every half inch.)

Imports Syncfusion.DocIO

Imports Syncfusion.DocIO.DLS


Public Class Form1

    Private colWidths() As Integer = {50, 28, 36, 36, 144, 27, 27, 36, 64, 36, 80}


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim doc As New WordDocument

        Dim section As WSection = doc.AddSection

        Dim paragraph As WParagraph = section.AddParagraph


        Dim myStyle As IWParagraphStyle = CType(doc.AddParagraphStyle("myStyle"), IWParagraphStyle)

        myStyle.CharacterFormat.FontName = "Tahoma"

        myStyle.CharacterFormat.FontSize = 8

        myStyle.CharacterFormat.Bold = True


        Dim tabStop As Integer = 0

        For i As Integer = 0 To colWidths.Length - 2

            tabStop += colWidths(i)

            paragraph.ParagraphFormat.Tabs.AddTab(tabStop)

        Next


        paragraph.ApplyStyle("myStyle")


        paragraph.Text = "It's crackers to slip a rozzer the dropsy in snide."


        Dim fn As String = Application.StartupPath & "\Test.docx"

        doc.Save(fn, FormatType.Word2010)


        MessageBox.Show("File created in Word 2010 format: " & fn, "File Created", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

End Class

Jim Brower



KK K Kalai Selvi Syncfusion Team September 16, 2015 03:43 AM UTC

From: Brower, James
Sent: Tuesday, September 15, 2015 12:31 PM
To: Syncfusion Support <support@syncfusion.com>
Subject: RE: Syncfusion support community forum 120251, Retaining Format after New Line in DocIO, has been updated.


Sorry, I just saw your second forum message with a link to the correct sample.

After looking at your sample, I would guess that my problem came from creating a ParagraphStyle, then applying it to each paragraph. The proper way, I gather, is to set the character formatting options in the TextRange of the paragraph, rather than in the ParagraphStyle.

This accomplished what I need, but I’m not really sure why. The documentation doesn’t seem to explain any difference between these two ways of doing things.

Jim Brower


AP Arumuga Perumal S Syncfusion Team September 17, 2015 01:53 AM UTC

Hi James,

Thank you for your update.

We will update the proper way to use Paragraph Style and character format of TextRange in our documentation and will let you know once it has been published online.

Regards,
Arumuga Perumal S.


Loader.
Live Chat Icon For mobile
Up arrow icon