Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Sep 27, 2024 9:48 am

I making a small app to save richtexbox text to a .odt file Libbre Office format (C# .Net Winform)
(Using FreeSpire version 12.2)

Problem is that the saved file out
is long string line with no breaks (\n)

------Original Text-----------
Dashing through the snow
In a one-horse open sleigh
O'er the fields we go
Laughing all the way
Bells on bobtails ring
Making spirits bright
What fun it is to ride and sing
A sleighing song tonight, oh!
------------------------------
Code: Select all
   
               // Create a new document object
                Document document = new Document();
               
                // Add a section and a paragraph
                Section section = document.AddSection();               
                Paragraph paragraph = section.AddParagraph();
               
                 // Save File
                 document.SaveToFile(filePath, FileFormat.Odt);


----Save file Text---------
Dashing through the snow In a one-horse open sleigh O'er the fields we go Laughing all the way Bells on bobtails ring Making spirits bright What fun it is to ride and sing A sleighing song tonight, oh!
-----------------


Please help how to get the file formated as original in in Richtextbox?
Thanks

cafony1969
 
Posts: 2
Joined: Mon May 27, 2024 9:12 am

Sun Sep 29, 2024 3:10 am

Hello,

Thanks for your inquiry. You can refer to the following code to add a line break symbol and a carriage return symbol at the line break position. If you have any other questions, please feel free to write to me.
Code: Select all
  // Get the value in richtexbox text
    string richTextValue = richTextBox1.Text;
    // Create a new document object
    Document document = new Document();
    // Add a section and a paragraph
    Section section = document.AddSection();
    Paragraph paragraph = section.AddParagraph();
    // Add specific separators between rows
    string[] lines = richTextBox1.Lines;
    string combinedText = string.Join("\r\n", lines);
    // Save Text
    paragraph.AppendText(combinedText);
    // Save File
    document.SaveToFile(@"test.odt", FileFormat.Odt);

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 306
Joined: Mon Jul 15, 2024 5:40 am

Thu Oct 03, 2024 9:28 am

Thank you very much
It works
Now I can save to Libbre Office .odt file format
:-)

cafony1969
 
Posts: 2
Joined: Mon May 27, 2024 9:12 am

Return to Spire.Doc

cron