Free Support Forum - aspose.com

Strange table behaviour

Hi

I'm having a very strange problem when building tables: it seems the first cell of the second row of the first table is appearing vertically aligned (or the column width is just enough for one text character, and the right table border is out of sync with the first row. All other columns/rows of all subsequent tables are fine. I run the code below in a loop, so each new table is built using the exact same code, and so it seems pretty strange to me that the first table comes out like this and the rest are fine

I've attached my resulting file. Clicking the column border causes the the alignment/width to correct itself, but we can't have this appearing on the reports drawn by the various system users.

If anyone has any idea why this might be happening, could you please let me know. We're using MS Word 2003 and Aspose.Word 3.1.7.0. If this has something to do with MS Word, does anyone know of a workaround? If this can be fixed using different Aspose methods, does anyone have any suggestions?

Thanks!!

Here is some of the code I used to build the table:



_builder.StartTable();


#region Headers

_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(2.82);

_builder.Font.Bold = true;

_builder.Font.Underline = Underline.Single;

_builder.Write("Daily Costs");


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);

_builder.Write("Cur");


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);

_builder.Write("Price");


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);

_builder.Write("Qty");


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);

_builder.Write("Total");

_builder.EndRow();

#endregion


_builder.Font.Underline = Underline.None;

_builder.Font.Bold = false;


DataView dvDaily = new DataView(_dsData.Tables["Items"]);

dvDaily.RowFilter = String.Format("GroupName = '{0}' AND TourSizeName = '{1}' AND CostingGroupOrder = {2} AND ConsumeDay = {3} AND Total <> 0", row["GroupName"].ToString().Replace("'", "''"), row["TourSizeName"].ToString(), row["CostingGroupOrder"].ToString(), row["ConsumeDay"].ToString());

dvDaily.Sort = "ServiceOrder, ItineraryNumber";


double fontSize = _builder.Font.Size;

_builder.Font.Size = 10;


if (dvDaily.Count > 0 && Convert.ToBoolean(_dsData.Tables["Parameters"].Rows[0]["ShowLineItems"]))

{

#region Insert Daily Costs

foreach (DataRowView rowDaily in dvDaily)

{

_dailyTotal += Convert.ToDouble(rowDaily.Row["Total"]) * Convert.ToDouble(rowDaily.Row["ExchangeRate"]);

_costingGroupTotal += Convert.ToDouble(rowDaily.Row["Total"]) * Convert.ToDouble(rowDaily.Row["ExchangeRate"]);

_total += Convert.ToDouble(rowDaily.Row["Total"]) * Convert.ToDouble(rowDaily.Row["ExchangeRate"]);


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(2.82);

_builder.Write(rowDaily["ServiceDescription"].ToString());


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);

_builder.CellFormat.HorizontalMerge = CellMerge.Previous;


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);

_builder.EndRow();


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(2.82);

_builder.Write(" " + rowDaily["ServiceBasisType"].ToString());


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);

_builder.Write(rowDaily["CurrencyCode"].ToString());


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);

_builder.Write(Convert.ToDouble(rowDaily["SellPrice"]).ToString("#,###,##0.00"));


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(0.5);

_builder.Write(Convert.ToDouble(rowDaily["Qty"]).ToString("#,###,##0.00"));


_builder.InsertCell();

_builder.CellFormat.Width = WordConvert.InchToPoint(1.13);

_builder.Write(Convert.ToDouble(rowDaily["Total"]).ToString("#,###,##0.00"));

_builder.EndRow();

}

#endregion

}



Hi,

Thank you for considering Aspose.

If you want the cells to be horizontally merged, you should set

_builder.CellFormat.HorizontalMerge = CellMerge.First;

for the first merged cell.

See here for a code sample:

http://www.aspose.com/Products/Aspose.Word/Api/Aspose.Word.CellFormat.HorizontalMerge.html

Hi!!

Thanks for getting back to me so quickly! Thanks for the help - using CellMerge.First seems to have solved the problem quite thoroughly!!

Thanks again!!

Regards

Angela