Hi,
Here is the method that I am using to create the table. I’ve renamed some classes in this example. Attached is the output I am getting (CurrentOutput.doc) and the output that I am looking to get (DesiredOutput.doc). The part you should look at is on the second page of both documents. Essentially, if I open the document after using Aspose.Words to generate the table, manually select the table and, from the context menu, choose “AutoFit > AutoFit to Contents” then I get the desired result. Not sure what happened to this feature in your component. It seems like its not adhering to the default behavior of MS Word which I believe is “AutoFit to Contents”. Thanks for your help.
–Paul
private void AddMatrixTable(BizObject _ipo, Document doc)
{
/*move to the end of the document, add a page break and output the table */
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.PageBreak);
//add title
Aspose.Words.Font f = builder.Font;
f.Name = "Tahoma";
f.Size = 12;
f.Bold = true;
f.Color = System.Drawing.Color.FromArgb(118, 146, 102);
builder.Write("Projection Matrix Table");
builder.InsertBreak(BreakType.LineBreak);
f.Color = System.Drawing.Color.FromArgb(79, 98, 40);
f.Size = 12;
//insert a line break
builder.InsertBreak(BreakType.LineBreak);
builder.InsertBreak(BreakType.LineBreak);
builder.InsertBreak(BreakType.LineBreak);
f.Size = 8;
builder.RowFormat.Alignment = RowAlignment.Center;
builder.RowFormat.TopPadding = 5;
builder.Write("Matrix X Axis Title Goes Here");
//draw the table
Table tbl = builder.StartTable();
builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
//builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Bottom;
f.Size = 10;
builder.InsertCell();
builder.CellFormat.Borders.LineStyle = LineStyle.None;
builder.Writeln("");
//start with the range column headers
builder.InsertCell();
builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
builder.Writeln("");
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
f.Color = System.Drawing.Color.FromArgb(79, 98, 40);
builder.InsertCell();
builder.Writeln("-40%");
builder.InsertCell();
builder.Writeln("-30%");
builder.InsertCell();
builder.Writeln("-20%");
builder.InsertCell();
builder.Writeln("-10%");
builder.InsertCell();
builder.Writeln("0%");
builder.InsertCell();
builder.Writeln("10%");
builder.InsertCell();
builder.Writeln("20%");
builder.InsertCell();
builder.Writeln("30%");
builder.InsertCell();
builder.Writeln("40%");
builder.EndRow();
//now, write a row for each target
bool yAxisWritten = false;
for (int i = 0; i < _ipo.objs.Count; i++)
{
BizSubObject call = _ipo.objs[i].sub1;
BizSubObject put = _ipo.objs[i].sub2;
double numToBuy = put.Qty;
double numToBuyMax = call.EqQty / call.Multiplier;
double percentPutBuy = numToBuy / numToBuyMax;
builder.InsertCell();
if (!yAxisWritten)
{
builder.CellFormat.Orientation = TextOrientation.Upward;
f.Size = 8;
builder.Write("Matrix Y Axis Title Goes Here");
builder.CellFormat.VerticalMerge = CellMerge.First;
yAxisWritten = true;
}
else
{
builder.Writeln("");
builder.CellFormat.VerticalMerge = CellMerge.Previous;
}
builder.CellFormat.Borders.LineStyle = LineStyle.None;
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White;
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
f.Color = System.Drawing.Color.Black;
//output cell containing the target
f.Bold = true;
f.Size = 10;
builder.InsertCell();
builder.CellFormat.Orientation = TextOrientation.Horizontal;
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Hairline;
builder.Writeln(call.TargetPrice.ToString());
f.Bold = false;
if (i == _ipo.SelectedIndex)
{
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
}
else
{
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(219, 229, 241);
f.Color = System.Drawing.Color.FromArgb(79, 98, 40);
}
//output a cell for each value in the range
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * -40d).ToString("N1") + "%");
if (i == _ipo.SelectedIndex)
{
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.FromArgb(255, 255, 153);
}
else
{
builder.CellFormat.Shading.Texture = TextureIndex.TextureSolid;
builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White;
builder.CellFormat.Shading.ForegroundPatternColor = System.Drawing.Color.White;
f.Color = System.Drawing.Color.Black;
}
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * -30d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * -20d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * -10d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * 0d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * 10d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * 20d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * 30d).ToString("N1") + "%");
builder.InsertCell();
builder.Writeln(((1d - percentPutBuy) * 40d).ToString("N1") + "%");
builder.EndRow();
}
builder.EndTable();
}