找回密码
 立即注册

QQ登录

只需一步,快速开始

[已处理] 行高设置

lud
论坛元老   /  发表于:2012-1-3 17:18  /   查看:6110  /  回复:6
请问Spread的行高怎样自动适应高度,我有换行的数据

6 个回复

正序浏览
iceman
社区贡献组   /  发表于:2012-1-13 11:36:00
7#

回复 6# lud 的帖子

不客气哈~
回复 使用道具 举报
lud
论坛元老   /  发表于:2012-1-13 11:34:00
6#
问题解决了 :-D
回复 使用道具 举报
lud
论坛元老   /  发表于:2012-1-13 11:32:00
5#
恩,谢谢版主
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-1-12 17:51:00
地板

回复 3# lud 的帖子

lud 你好,感谢把问题反馈给我们,确实有该问题出现,现在需要自定义方法去计算 Row 高,请尝试下面代码:

  1.          private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.                 FarPoint.Win.Spread.CellType.TextCellType textCellType=new FarPoint.Win.Spread.CellType.TextCellType();
  4.                 textCellType.WordWrap = true;
  5.                 this.fpSpread1.ActiveSheet.Columns[0].CellType = textCellType;
  6.                 this.fpSpread1_Sheet1.AddSpanCell(0, 0, 2, 2);
  7.                 this.fpSpread1_Sheet1.Cells[0, 0].Text = "tetesttestessttestessttestessttestessttestesttestest";
  8.                 this.fpSpread1_Sheet1.Rows[0].Height = GetRowBestHeight(0,System.Drawing.Graphics.FromHwnd(new IntPtr()));
  9.         }
  10.         private float GetRowBestHeight(int viRow, System.Drawing.Graphics vgphGraphics)
  11.         {
  12.             int i = 0;
  13.             float bestHeight = 0;
  14.             SizeF bestSize = default(SizeF);
  15.             float width = 0;

  16.             while ((i < this.fpSpread1_Sheet1.ColumnCount - 1))
  17.             {
  18.                 // Calculate width of cell based on column span
  19.                 width = 0;
  20.                 for (int iTemp = 0; iTemp <= (this.fpSpread1_Sheet1.Cells[viRow, i].ColumnSpan - 1); iTemp++)
  21.                 {
  22.                     width += this.fpSpread1_Sheet1.Columns[i + iTemp].Width;
  23.                 }
  24.                 bestSize = vgphGraphics.MeasureString(this.fpSpread1_Sheet1.Cells[viRow, i].Text,new Font("Microsoft Sans Serif",(float)(8.25)), Convert.ToInt32(width));
  25.                 if (bestSize.Height > bestHeight)
  26.                 {
  27.                     bestHeight = bestSize.Height;
  28.                 }
  29.                 i += this.fpSpread1_Sheet1.Cells[viRow, i].ColumnSpan;
  30.             }
  31.             return bestHeight;
  32.         }
复制代码
回复 使用道具 举报
lud
论坛元老   /  发表于:2012-1-12 17:06:00
板凳
版主,这个设置行高有问题,不知道你有没有试过合并的单元格操作,你会看到内容越多,高度变化越大
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-1-4 09:20:00
沙发

回复 1# lud 的帖子

lud 你好,
1.折行功能可以通过 TextCellType 的 WordWrap 属性来实现。
2.Spread 提供 GetPreferredHeight() 方法去获取当前行的最小高度。
请通过以下代码测试:

  1. FarPoint.Win.Spread.CellType.TextCellType textCellType=new FarPoint.Win.Spread.CellType.TextCellType();
  2. textCellType.WordWrap = true;
  3. this.fpSpread1.ActiveSheet.Columns[0].CellType = textCellType;
  4. this.fpSpread1_Sheet1.Cells[0, 0].Text = &quot;testtesttesttesttesttesttesttest&quot;;
  5.              this.fpSpread1_Sheet1.Rows[0].Height=this.fpSpread1_Sheet1.Rows[0].GetPreferredHeight();
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部