2017-11-07 6 views
0

テーブルの幅と高さを指定しようとしています。Aspose C#DOCXテーブルを無視するセルの幅と高さ

最終的な目標は、最初の列が約90%、最後の列が残りの10%を取ることです。 私は多くの異なる組み合わせを試しましたが、単語はそれを無視するようです。

マイドキュメントBuilderのコードはここにある:

 var table = docBuilder.StartTable(); 
     docBuilder.InsertCell(); 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90); 
     docBuilder.CellFormat.ClearFormatting(); 
     docBuilder.Font.Bold = true; 
     docBuilder.Font.Name = Stylings.TITLEFONT; 
     docBuilder.Font.Size = Stylings.TITLESIZE1; 
     docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
     docBuilder.Write("Description"); 

     var cell = docBuilder.InsertCell(); 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); 
     docBuilder.CellFormat.FitText = false;    
     docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
     docBuilder.Font.Name = Stylings.TITLEFONT; 
     docBuilder.Font.Size = Stylings.TITLESIZE1; 
     docBuilder.Font.Bold = true; 
     docBuilder.Write("Amount (inc GST)"); 
     docBuilder.EndRow(); 

     docBuilder.InsertCell(); 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90); 
     docBuilder.Font.Bold = false; 
     docBuilder.Font.Name = Stylings.NORMALFONT; 
     docBuilder.Font.Size = Stylings.NORMALSIZE1; 
     docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; 
     docBuilder.Write(description); 

     docBuilder.InsertCell(); 
     docBuilder.RowFormat.HeightRule = HeightRule.AtLeast; 
     docBuilder.RowFormat.Height = 5; 
     docBuilder.CellFormat.FitText = false; 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); 
     docBuilder.Font.Bold = false; 
     docBuilder.Font.Name = Stylings.NORMALFONT; 
     docBuilder.Font.Size = Stylings.NORMALSIZE1; 
     docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; 
     docBuilder.Write(total.ToString("C")); 
     docBuilder.EndRow(); 

     docBuilder.InsertCell(); 
     docBuilder.RowFormat.HeightRule = HeightRule.Auto; 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90); 

     docBuilder.InsertCell(); 
     docBuilder.CellFormat.FitText = false; 
     docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); 
     docBuilder.Font.Bold = false; 
     docBuilder.Font.Name = Stylings.NORMALFONT; 
     docBuilder.Font.Size = Stylings.NORMALSIZE1; 
     docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; 
     docBuilder.Write(total.ToString("C")); 
     docBuilder.EndRow(); 

     //Table Formatting 
     table.AutoFit(AutoFitBehavior.FixedColumnWidths); 
     table.PreferredWidth = PreferredWidth.FromPercent(100); 
     docBuilder.EndTable(); 

答えて

2

異なる相対的なサイズのセルでテーブルを作成するために、次のサンプルコードスニペットを使用してください。

私は開発者エバンジェリストとしてAsposeを使用しています。

// Insert a table row made up two cells which have different preferred widths. 
Table table = builder.StartTable(); 

// Insert a relative (90 percent) sized cell. 
builder.InsertCell(); 
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90); 
builder.CellFormat.ClearFormatting(); 
builder.Font.Bold = true; 
builder.Font.Name = "Arial"; 
builder.Font.Size = 10; 
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
builder.Writeln("Description"); 

// Insert a relative (10 percent) sized cell. 
builder.InsertCell(); 
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); 
builder.CellFormat.ClearFormatting(); 
builder.Font.Bold = true; 
builder.Font.Name = "Arial"; 
builder.Font.Size = 10; 
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
builder.Writeln("Amount (inc GST)"); 
builder.EndRow(); 

// Insert a relative (90 percent) sized cell. 
builder.InsertCell(); 
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(90); 
builder.CellFormat.ClearFormatting(); 
builder.Font.Bold = true; 
builder.Font.Name = "Arial"; 
builder.Font.Size = 10; 
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
builder.Writeln("Aspose.Words for .NET 17.10"); 

// Insert a relative (10 percent) sized cell. 
builder.InsertCell(); 
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); 
builder.CellFormat.ClearFormatting(); 
builder.Font.Bold = true; 
builder.Font.Name = "Arial"; 
builder.Font.Size = 10; 
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; 
builder.Writeln("1000.00"); 
builder.EndRow(); 
+0

ビルダーです.CellFormat.ClearFormatting();それはこの作品を作っているのですか? – michael

+0

いいえ、PreferredWidth of Cellが期待される結果を生成しています。 –

関連する問題