找回密码
 立即注册

QQ登录

只需一步,快速开始

UpLin

中级会员

2

主题

8

帖子

684

积分

中级会员

积分
684

活字格认证

最新发帖
UpLin
中级会员   /  发表于:2015-7-30 17:09  /   查看:10646  /  回复:15
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;
使用这种方法不能获取到单元格文字与边框有距离的真实高度。如:

QQ截图20150730171026.png
还有个问题就是 height和width的单位是什么呢?我想将word的表格转换到excel中,该如何换算

15 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2015-7-30 17:47:00
沙发
回复 1楼UpLin的帖子

TX 的默认单位为 twips。

单元格和边距您还需要考虑 TableCellFormat  中的BottomTextDistance  、LeftTextDistance、TopTextDistance和 RightTextDistance因素。相当于Margin
回复 使用道具 举报
UpLin
中级会员   /  发表于:2015-7-31 10:10:00
板凳
回复 2楼iceman的帖子

BottomTextDistance 和TopTextDistance 值都为0  只有LeftTextDistance和RightTextDistance有值
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-7-31 14:41:00
地板
回复 3楼UpLin的帖子

请问您是需要获取文字和上边框的距离对吗?
Untitled.png (15.63 KB, 下载次数: 150)
回复 使用道具 举报
UpLin
中级会员   /  发表于:2015-7-31 14:43:00
5#
回复 4楼iceman的帖子

获取整个单元格的高度。也就是要文字到上边框和下边框的距离
回复 使用道具 举报
UpLin
中级会员   /  发表于:2015-7-31 16:40:00
6#
回复 4楼iceman的帖子

版主 demo好了吗 谢谢
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-7-31 17:56:00
7#
回复 6楼UpLin的帖子

你的问题我们已经收到了。

你的Demo制作需要时间,很抱歉给你带来的不便。
Demo完成后下周第一时间给你回复。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
UpLin
中级会员   /  发表于:2015-8-19 16:34:00
8#
回复 7楼Alice的帖子

版主, 说好的demo呢~
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2015-8-19 19:16:00
9#
回复 1楼UpLin的帖子

非常抱歉让您久等了。以下是测试代码,主要是通过计算当前单元格最上部文字位置及最下部文字位置和单元格的上下文字边距来实现的:

  1. private void addTableToolStripMenuItem_Click(object sender, EventArgs e)
  2.         {
  3.             this.textControl1.Tables.Add(10,10,11);
  4.         }

  5.         private void getRowHeightToolStripMenuItem_Click(object sender, EventArgs e)
  6.         {
  7.             TXTextControl.Table tb = this.textControl1.Tables.GetItem(11);

  8.             foreach (TXTextControl.TableCell cell in tb.Cells)
  9.             {
  10.                int height =  getTextHeight(cell, this.textControl1);
  11.             }
  12.         }

  13.         /// <summary>
  14.         /// Iterates over all cells within the row and search the highest cell.
  15.         /// </summary>
  16.         /// <param name="cell"></param>
  17.         /// <param name="table">Contains the cell</param>
  18.         /// <param name="textControl">Contains the table and the cell</param>
  19.         /// <returns>Height of the row</returns>
  20.         int getHeight(TXTextControl.TableCell cell, TXTextControl.Table table, TXTextControl.TextControl textControl)
  21.         {
  22.             int absoluteHeight = -1;
  23.             for (int i = 1; i <= table.Columns.Count; i++)
  24.             {
  25.                 int relativeCellHeight = getTextHeight(table.Cells.GetItem(cell.Row, i), textControl);
  26.                 if (relativeCellHeight > absoluteHeight)
  27.                 {
  28.                     absoluteHeight = relativeCellHeight;
  29.                 }
  30.             }
  31.             return absoluteHeight;
  32.         }

  33.         /// <summary>
  34.         /// Calculates the height with help of the bounds of the first and last character of the TableCell.
  35.         /// The TextDistances are considered.
  36.         /// </summary>
  37.         /// <param name="cell">Contains the text</param>
  38.         /// <param name="textControl">Required to get the TextChar</param>
  39.         /// <returns>The minimum height of the cell.</returns>
  40.         int getTextHeight(TXTextControl.TableCell cell, TXTextControl.TextControl textControl)
  41.         {
  42.             TXTextControl.TextChar firstTextChar = textControl.TextChars[cell.Start];
  43.             TXTextControl.TextChar lastTextChar = textControl.TextChars[cell.Start + cell.Length];

  44.             return lastTextChar.Bounds.Bottom - firstTextChar.Bounds.Top + cell.CellFormat.BottomTextDistance + cell.CellFormat.TopTextDistance;
  45.         }
复制代码
回复 使用道具 举报
UpLin
中级会员   /  发表于:2015-8-20 13:46:00
10#
回复 9楼iceman的帖子

不行啊  cell.CellFormat.BottomTextDistance + cell.CellFormat.TopTextDistance 这两个值 始终是为0的
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部