I'm generating a word document using Aspose.Words(Evaluation mode) for .Net in which I'm building a table as following

   Document doc = new Document();
   DocumentBuilder builder = new DocumentBuilder(doc);
   Table table = builder.StartTable();
   for (int i = 0; i < 5; i++)
   {
       for(int j = 0; j < 20; j++)
       {
            builder.InsertCell();
            builder.Write("Column : "+ j.toString());
        }
     builder.EndRow();
   }
   builder.EndTable();
   doc.Save(ms, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(SaveFormat.Doc));
   FileStream file = new FileStream(@"c:\NewDoc.doc", FileMode.Create, FileAccess.Write);
   ms.WriteTo(file);
   file.Close();
   ms.Close();

Now this code gives following word file with invisible columns, it should give 20 columns

Table with truncated columns .

Is there any way to break invisible columns to next page?

1

There are 1 answers

2
Saqib Razzaq On BEST ANSWER

Rows can go to next page, not columns, it is the behavior of Microsoft Word. You can change the design and formatting of the document to make all columns visible. Below are few pointers.

  1. Reduce the page margins (left and right)
  2. Make the cells width fixed. This way, the text inside each cell will break downwards, if more characters found.
  3. Change orientation to landscape, you will have a wider page.

Check the related articles and code sample on Aspose.Words documentation website.

Try the updated code sample below:

string dst = dataDir + "table.doc";

Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set margins
doc.FirstSection.PageSetup.LeftMargin = 10;
//doc.FirstSection.PageSetup.TopMargin = 0;
doc.FirstSection.PageSetup.RightMargin = 10;
//doc.FirstSection.PageSetup.BottomMargin = 0;

// Set oriantation
doc.FirstSection.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;

Aspose.Words.Tables.Table table = builder.StartTable();

for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 20; j++)
    {
        builder.InsertCell();
        // Fixed width
        builder.CellFormat.Width = ConvertUtil.InchToPoint(0.5);
        builder.Write("Column : " + j);
    }
    builder.EndRow();
}
builder.EndTable();

// Set table auto fit behavior to fixed width columns
table.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(dst, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc));

I work with Aspose as a Developer Evangelist.