2

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?

4

1 回答 1

0

行可以转到下一页,而不是列,这是 Microsoft Word 的行为。您可以更改文档的设计和格式以使所有列可见。下面是几点建议。

  1. 缩小页边距(左右)
  2. 使单元格宽度固定。这样,如果发现更多字符,每个单元格内的文本将向下分解。
  3. 将方向更改为横向,您将拥有更宽的页面。

查看Aspose.Words 文档网站上的相关文章和代码示例。

试试下面更新的代码示例:

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

我与 Aspose 一起担任开发人员布道师。

于 2015-06-18T09:52:19.873 回答