Good day,
I merged document file using the following code which was successful.
Please how can I split it into two columns l ike in book form? Such that it will have two columns left and right with a vertical line at the center of each page (I.e. Divid each page into two columns with a vertical line at the center) without any third party dll file or assembly file.
Thank you.
Obi
Dim missing As Object = System.Type.Missing
Dim pageBreak As Object = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage
Dim outputFile As Object = outputFilename
Dim wordApplication As Microsoft.Office.Interop.Word._Application = New Microsoft.Office.Interop.Word.Application()
Try
Dim wordDocument As Microsoft.Office.Interop.Word.Document = wordApplication.Documents.Add(missing, missing, missing, missing)
Dim selection As Microsoft.Office.Interop.Word.Selection = wordApplication.Selection
Dim documentCount As Integer = filesToMerge.Length
Dim breakStop As Integer = 0
For Each file As String In filesToMerge
breakStop += 1
selection.InsertFile(file, missing, missing, missing, missing)
If insertPageBreaks AndAlso breakStop <> documentCount Then
selection.InsertBreak(pageBreak)
End If
Next
wordDocument.SaveAs(outputFile, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
wordDocument = Nothing
Catch ex As Exception
Throw ex
Finally
wordApplication.Quit(missing, missing, missing)
End Try
15 Answers, 1 is accepted
Hi Obi,
Microsoft.Office.Interop.Word is not a Telerik product, thus we do not provide Technical Support for it. I recommend posting on StackOverflow in the VB.NET and Winforms tags so you can get assistance from the developer community.
- Go to https://stackoverflow.com/questions/tagged/vb.net+winforms
- Click "Ask a Question"
Good luck!
Regards,
Lance | Manager Technical Support
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Sorry I posted it before I realised that I have to modify it. The question is meant for aspforums.
I have RadRichTextEditor control which I used to create and save documents using vb.net windows form. How can I split the saved document into two columns as in book form? Such that it will have two columns left and right with a vertical line at the center of each page (Divid each page into two columns with a vertical line at the center).
Thank you.
Hi Obi,
Thank you for clarifying that you are using RadRichTextEditor for the user to enter text. However this stull doesn't change my answer, you're saving the document using Microsoft.Office.Interop APIs.
We do not have any sample code for Microsoft.Office.Interop.Word.Document, so my recommendation is the same, post on StackOverflow. Here's an example question you can use: "How do I create a book-like page layout with Microsoft.Office.Interop.Word.Document?"
Regards,
Lance | Manager Technical Support
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
documents using vb.net windows form. How can I split the saved document
into two columns as in book form? Such that it will have two columns
left and right with a vertical line at the center of each page (Divid
each page into two columns with a vertical line at the center).
Thank you.
Hi Obi,
Yes, this is supported by RadRichTextEditor. You can use the following code to create the columns:
SectionColumnCollection sectionColumnCollection = new SectionColumnCollection(2, 35, true);
RadDocumentEditor editor = new RadDocumentEditor(radRichTextEditor1.Document);
editor.ChangeSectionColumns(sectionColumnCollection);
I hope this helps. Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
Thank you very much for understanding me. Please do you have any sample solution that I can look at?
I do not know where to place the code you gave me. I placed it to execute on button click and nothing happened.
Thank you so much.
Hi Obi,
Please review the RadRichTextEditor Section documentation, it explains that the RadRichTextEditor need to be in Paged layout mode in order for sections to be presented.
that is the mostly likely reason for not seeing any changed in the RichTextEditor.
Demo Code
Dimitar's answer shows you how you can have columns inside the component. Just to be clear, that is not the saved document, it is only what you see at runtime inside the RichTextEditor. For a saved document, you need to export it using a FormatProvider, luckily the DocxFormatProvider will retain the sections.
Expanded Demo
Here's a little more code for Dimitar's example. Assuming you have a radRichTextEditor1 in the form, the following code
Here's the result at runtime (left)
Here's the result after exporting to docx
Complete Demo and Example Code
If you would like to see demo code that put it all together, take the following steps:
- Launch the Telerik UI for WinForms Examples app
- This will be installed on your machine that you have UI for WinForms installed, here's a screenshot in the Start menu
- Navigate to RichTextEditor - Section Columns example
- Change the Columns to 2
- To see the code, click the C# button at the top
Telerik Support
If you would be willing to switch to UI for WinForms and Telerik Document Processing, you can use our libraries to help you achieve that goal.
I have reviewed your account and you have never had any UI for WinForms licenses, where did you get UI for WinForms from? How are you developing with UI for WinForms?
Here are two options to take care of the license problem
- You can get a new UI for WinForms license here or contact your sales rep.
- Have the owner of the license assign you as the licensed user here - Manage Licensed Users (they need to remove themselves from the license before assigning it to you)
If I didn't answer your question, please reply back with the answers to the questions I asked at the beginning of this reply.
Non-Telerik API Support
My first interpretation of your question is that you are not using Telerik UI for WinForms and are only asking for help with using Microsoft.Office.Interop.Word.Document to save a docx file with the desired format. That has no Telerik components involved, thus UI for WinForms or Telerik Document Processing methods are not applicable.
So that there is no further misunderstanding, if you have any further questions, please answer the following questions:
- Do you want have the columns in the application (inside the RadRichTextEditor)?
- Do you want the columns only in the saved document (in the saved docx file)?
- Or do you want both? (my attached demo does this)
Thank you for taking the time to ready this, I know it was a bit long.
Regards,
Lance | Manager Technical Support
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
Hello Obi,
My apologies, I forgot to convert the code to VB (you can always use our converter in the future https://converter.telerik.com/).
Imports System
Imports System.IO
Imports Telerik.WinForms.Documents.FormatProviders.OpenXml.Docx
Imports Telerik.WinForms.Documents.FormatProviders.Txt
Imports Telerik.WinForms.Documents.Model
Namespace DocColumns
Public Partial Class RadForm1
Inherits Telerik.WinControls.UI.RadForm
Public Sub New()
InitializeComponent()
Dim provider As TxtFormatProvider = New TxtFormatProvider()
radRichTextEditor1.Document = provider.Import(Helpers.ReallyLongText)
radRichTextEditor1.LayoutMode = DocumentLayoutMode.Paged
Dim sectionColumnCollection As SectionColumnCollection = New SectionColumnCollection(2, 30, False)
Dim editor As RadDocumentEditor = New RadDocumentEditor(radRichTextEditor1.Document)
editor.ChangeSectionColumns(sectionColumnCollection)
End Sub
Private Sub radButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim provider As DocxFormatProvider = New DocxFormatProvider()
Using output As FileStream = File.OpenWrite("Sample.docx")
Dim document As RadDocument = radRichTextEditor1.Document
provider.Export(document, output)
End Using
End Sub
End Class
End Namespace
Regards,
Lance | Manager Technical Support
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Thank you sir. I will give it a try and get back to you.
As for your question on license, I downloaded the experimental version and fell in love with the UI. Currently I have Devexpress on my system but I am looking at obtaining a license for Telerik once I'm done going through it. Thanks once again.
Hello Obi,
Please let us know if there's anything we can do to help during your tests.
During your trial, you have access to the technical support system where you can get fast turnaround and one-on-one help. We do our best to answer all public forum threads, but this can sometimes take a few days because Support Ticket cases always come first.
Here's how to open a ticket
- Make sure you are signed into telerik.com with the email address you used to download the trial license
- Go to Get Support | Your Account
- Select UI for WinForms, select RichTextEditor and enter your question
Regards,
Lance | Manager Technical Support
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
I want the columns only in already saved document (docx file). I have a file called text.docx my document folder. How can I achieve that?
Thank you.
Hello Obi,
My demo was just using plain text to keep things simple. Where the original text comes from doesn't really matter. The point of the demo was to show you how to use the RadRichTextEditor's columns feature.
If you didn't read the documentation I provided and are wondering where to find information on how to import an existing docx file, find that here https://docs.telerik.com/devtools/winforms/controls/richtexteditor/import-export/docx/docxformatprovider#import
you will find that you can use the file's path, like this:
Getting Started Information
Please put aside 15-30 minutes and just browse the RadRichTextEditor documentation so you know where to find the easier getting started information. The document format providers are a crucial thing to know how to use as they are the mechanism the load and saves data.
It will save you a bunch of time and headache because you will know where to find the answers to most questions quickly instead of having to wait 3 days or longer for a forum reply.
*Support Tickets have a <24 hr reply.
Using Only Telerik Document Processing
If you are asking how to do this without the UI for WinForms RichTextEditor, you will need to open a Support Ticket with the Document Processing Team as what you're requesting is a custom development request to build a document ingestion and modification pipeline demo.
Self-Help
Alternatively, if you would like to learn how to do it on your own with a support ticket follow these steps
- Go to the Word Processing Library Overview documentation and study how the libraries work.
- Next, go to the Getting Started article will show you how to get started.
- Go to the Model Overview documentation and learn how the document model is setup (very important)
- Next, go to the Sections documentation to learn how to use Sections
- Import your existing docx file using the Import
- Work on your document to create the columns
- Export your document to a new file using Export
Again, there is no demo for this no-UI approach, you will need to experiment based on the original format of your document. Open a Support Ticket if you have any trouble.
Regards,
Lance | Manager Technical Support
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).
I read a bit of the documentation. I was actually using the code below to load and split docx into two columns then save without importing it into any richtexteditor control, though I used spire.doc dll trial version. I was wondering if it is achievable using some Telerik code or must I import. Any clue?
Dim document As Spire.Doc.Document = New Spire.Doc.Document
document.LoadFromFile(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\test.docx")
document.Sections(0).AddColumn(100.0F, 20.0F)
document.Sections(0).PageSetup.ColumnsLineBetween = True
Dim output As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\NewFolder\test.docx"
document.SaveToFile(output, FileFormat.Docx2010)
Hello Obi,
Please see this section in my last reply about your request:
Since you are clearly not looking to use UI for WinForms, I am closing this forum thread. Please click the link in my last reply (in that screenshot) to open a Support Ticket to get help with your request,
> Note: You can include that last code snippet in your ticket, it will be helpful to the team. I also recommend sending them the demo I sent you. You can say "I would like to do this, but without Telerik UI for WinForms".
Regards,
Lance | Manager Technical Support
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).