2017-11-07 14 views
0

테이블의 너비와 높이를 지정하려고합니다.Aspose C# 테이블을 무시하는 DOCX 셀 너비 및 높이

최종 목표는 첫 번째 열이 약 90 %, 마지막 열이 나머지 10 %를 차지하는 것입니다. 여러 가지 조합을 시도했지만 단어가이를 무시하는 것 같습니다.

내 문서 빌더 코드는 여기에 있습니다 :

 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

입니다. builder.CellFormat.ClearFormatting(); 그게이 일을 만들고있는거야? – michael

+0

아니요, PreferredWidth of Cell이 예상 결과를 생성 중입니다. –