TableCell单元格的高度
TXTextControl.Line lstart = wordControl.Lines.GetItem(cell.Start - 1);TXTextControl.Line lend = wordControl.Lines.GetItem(cell.Start + cell.Length - 1);
int height = lend.TextBounds.Top - lstart.TextBounds.Top + lend.TextBounds.Height;
使用这种方法不能获取到单元格文字与边框有距离的真实高度。如:
还有个问题就是 height和width的单位是什么呢?我想将word的表格转换到excel中,该如何换算 回复 1楼UpLin的帖子
TX 的默认单位为 twips。
单元格和边距您还需要考虑 TableCellFormat中的BottomTextDistance、LeftTextDistance、TopTextDistance和 RightTextDistance因素。相当于Margin 回复 2楼iceman的帖子
BottomTextDistance 和TopTextDistance 值都为0只有LeftTextDistance和RightTextDistance有值 回复 3楼UpLin的帖子
请问您是需要获取文字和上边框的距离对吗?
确认之后我们会给你提供Demo,协助解决。 回复 4楼iceman的帖子
获取整个单元格的高度。也就是要文字到上边框和下边框的距离 回复 4楼iceman的帖子
版主 demo好了吗 谢谢 回复 6楼UpLin的帖子
你的问题我们已经收到了。
你的Demo制作需要时间,很抱歉给你带来的不便。
Demo完成后下周第一时间给你回复。 回复 7楼Alice的帖子
版主, 说好的demo呢~ 回复 1楼UpLin的帖子
非常抱歉让您久等了。以下是测试代码,主要是通过计算当前单元格最上部文字位置及最下部文字位置和单元格的上下文字边距来实现的:
private void addTableToolStripMenuItem_Click(object sender, EventArgs e)
{
this.textControl1.Tables.Add(10,10,11);
}
private void getRowHeightToolStripMenuItem_Click(object sender, EventArgs e)
{
TXTextControl.Table tb = this.textControl1.Tables.GetItem(11);
foreach (TXTextControl.TableCell cell in tb.Cells)
{
int height =getTextHeight(cell, this.textControl1);
}
}
/// <summary>
/// Iterates over all cells within the row and search the highest cell.
/// </summary>
/// <param name="cell"></param>
/// <param name="table">Contains the cell</param>
/// <param name="textControl">Contains the table and the cell</param>
/// <returns>Height of the row</returns>
int getHeight(TXTextControl.TableCell cell, TXTextControl.Table table, TXTextControl.TextControl textControl)
{
int absoluteHeight = -1;
for (int i = 1; i <= table.Columns.Count; i++)
{
int relativeCellHeight = getTextHeight(table.Cells.GetItem(cell.Row, i), textControl);
if (relativeCellHeight > absoluteHeight)
{
absoluteHeight = relativeCellHeight;
}
}
return absoluteHeight;
}
/// <summary>
/// Calculates the height with help of the bounds of the first and last character of the TableCell.
/// The TextDistances are considered.
/// </summary>
/// <param name="cell">Contains the text</param>
/// <param name="textControl">Required to get the TextChar</param>
/// <returns>The minimum height of the cell.</returns>
int getTextHeight(TXTextControl.TableCell cell, TXTextControl.TextControl textControl)
{
TXTextControl.TextChar firstTextChar = textControl.TextChars;
TXTextControl.TextChar lastTextChar = textControl.TextChars;
return lastTextChar.Bounds.Bottom - firstTextChar.Bounds.Top + cell.CellFormat.BottomTextDistance + cell.CellFormat.TopTextDistance;
}
回复 9楼iceman的帖子
不行啊cell.CellFormat.BottomTextDistance + cell.CellFormat.TopTextDistance 这两个值 始终是为0的
页:
[1]
2