Text columns Insertion into document and insert content using C#

HI,
I am looking for a way to Create Text Columns like 3-4 and flow the data into it later.
I tried this before and i remeber it working .But now its not working .
I also tried as mentioned in below ticket
Insert Text columns into document and insert content using C# - Free Support Forum - aspose.com
and also in below documention
TextColumn Class | Aspose.Words for .NET
I am also attaching generated document for reference .
MultiColumn.docx (17.7 KB)

@tejkamalleo

Cause

It seems you’re trying to create text columns in a document using Aspose.Words for .NET, but you’re facing issues with the implementation that previously worked for you. This could be due to changes in your code or the library version.

Solution

To create text columns in a document, you can use the TextColumn class. Here’s a simple example of how to set up a document with multiple columns and flow text into them:

Code

using Aspose.Words;
using Aspose.Words.Layout;

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set up the page to have multiple columns
builder.PageSetup.TextColumns.Clear();
builder.PageSetup.TextColumns.Add(new TextColumn(100)); // First column
builder.PageSetup.TextColumns.Add(new TextColumn(100)); // Second column
builder.PageSetup.TextColumns.Add(new TextColumn(100)); // Third column

// Insert text into the columns
builder.Write("This is some text that will flow into the columns. ");
builder.InsertBreak(BreakType.ColumnBreak);
builder.Write("This text will appear in the second column. ");
builder.InsertBreak(BreakType.ColumnBreak);
builder.Write("And this is in the third column.");

// Save the document
doc.Save("MultiColumn.docx");

This code creates a document with three columns and adds text that flows into each column. Adjust the column widths as needed.

Next Steps

  1. Ensure you have the latest version of Aspose.Words for .NET.
  2. Test the provided code snippet to see if it meets your requirements.
  3. If you encounter any issues, check for any specific errors or behaviors that might indicate what’s going wrong.

If you need further assistance or clarification, please feel free to reach out!

Logic didnt work and also got build failures
build failed because the following methods and constructors do not exist in the Aspose.Words .NET API:

  • TextColumns.Clear() does not exist.
  • TextColumns.Add() does not exist.
  • new TextColumn(width) constructor does not exist.

These methods and constructors are not available in Aspose.Words for .NET. They may exist in another language’s API (like Java), but not in .NET.

In Aspose.Words .NET, you must:

  • Use SetCount(n) to set the number of columns.
  • Set the width and spacing for each column using the TextColumns collection, e.g. columns[0].Width = 100;.

Your current working code (see your last attachment) is the correct way for .NET.

@tejkamalleo The code suggested by AI is not quite correct. You can use the following simple code to create text columns:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// SetCultureAttribute number of text columns
builder.PageSetup.TextColumns.SetCount(3);
builder.PageSetup.TextColumns[0].Width = 100;
builder.PageSetup.TextColumns[1].Width = 100;
builder.PageSetup.TextColumns[2].Width = 100;

builder.Write("The first column");
builder.InsertBreak(BreakType.ColumnBreak);
builder.Write("The second column");
builder.InsertBreak(BreakType.ColumnBreak);
builder.Write("The third column");

doc.Save(@"C:\Temp\out.docx");

out.docx (7.0 KB)

HI @alexey.noskov ,
Thans for the suggestion but as mentioned in my very first request i tried this code already and it didnt work .
I tried again. Attaching the result . It seems that it is not working.
Can you please check from you side as well please.
out.docx (17.7 KB)

@tejkamalleo Your output looks correct. There are three test columns, just as expected:

Thanks @alexey.noskov .
Something weird is going on the exact same file when i open i see as attached screenshot.

Not sure what is happeneing here.

@tejkamalleo Looks like you are viewing document in Web mode. Please try switching to print layout:

Such a Silly mistake .You are amazing.
Thanks for your time @alexey.noskov