This is a migrated thread and some comments may be shown as answers.
Split word document into two columns in VB.Net
15 Answers 10 Views
This is a migrated thread and some comments may be shown as answers.
obi
Top achievements
Rank 1
obi asked on 15 Sep 2020, 02:31 PM

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

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 15 Sep 2020, 02:42 PM

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.

  1. Go to https://stackoverflow.com/questions/tagged/vb.net+winforms 
  2. 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/.

0
obi
Top achievements
Rank 1
answered on 15 Sep 2020, 03:23 PM

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.

0
Lance | Manager Technical Support
Telerik team
answered on 15 Sep 2020, 05:38 PM

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).

0
obi
Top achievements
Rank 1
answered on 28 Sep 2020, 11:45 AM
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.
0
Dimitar
Telerik team
answered on 29 Sep 2020, 10:54 AM

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);
More information is available here: Section Columns.

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).

0
obi
Top achievements
Rank 1
answered on 01 Oct 2020, 03:02 PM

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.

0
Lance | Manager Technical Support
Telerik team
answered on 01 Oct 2020, 05:46 PM

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:

  1. 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
  2. Navigate to RichTextEditor - Section Columns example
  3. Change the Columns to 2
  4. 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

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).

0
Lance | Manager Technical Support
Telerik team
answered on 01 Oct 2020, 05:50 PM

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/.

0
obi
Top achievements
Rank 1
answered on 02 Oct 2020, 01:14 PM

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.

0
Lance | Manager Technical Support
Telerik team
answered on 02 Oct 2020, 02:13 PM

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

  1. Make sure you are signed into telerik.com with the email address you used to download the trial license
  2. Go to Get Support | Your Account
  3. 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).

0
obi
Top achievements
Rank 1
answered on 02 Oct 2020, 02:30 PM
OK thanks 
0
obi
Top achievements
Rank 1
answered on 02 Oct 2020, 06:59 PM

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.

0
Lance | Manager Technical Support
Telerik team
answered on 02 Oct 2020, 07:55 PM

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

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).

0