求解替换表格列内容
想把表格中主诉、现病史这些field后面的字符内容(普通字符,不是field)用程序替换成需要的文字,请版主指导一下,谢谢! 基本想法就是找到关键字,然后确定selection start和length,然后替换文字。不过现在还有点问题,Find方法好像找不到Table中的文本,明天再继续调试。
参考代码如下:
int position = this.textControl1.Find("主诉",0,FindOptions.NoMessageBox);
this.textControl1.Selection.Start = position;
int row = -1;
for (int i = 1; i < this.textControl1.Tables.GetItem(10).Rows.Count - 1; i++)
{
if (this.textControl1.Tables.GetItem(10).Cells.GetItem(i, 1).Text.StartsWith("主诉"))
{
row = i;
break;
}
}
this.textControl1.Selection.Length = this.textControl1.Tables.GetItem(10).Cells.GetItem(row, 1).Text.Length;
this.textControl1.Selection.Text = "替换"; 修改后,可以使用了。
private void Form1_Load(object sender, EventArgs e)
{
int tableID = 10;
textControl1.Tables.Add(3, 1, tableID);
TXTextControl.Table table = textControl1.Tables.GetItem(tableID);
table.Cells.GetItem(1, 1).Text = "主诉:右肩关节上举疼痛7天。";
}
private void button1_Click(object sender, EventArgs e)
{
int position = 0;
this.textControl1.InputPosition = new InputPosition(position);
position = this.textControl1.Find("主诉") + 3;
this.textControl1.Selection.Start = position;
int row = -1;
for (int i = 1; i < this.textControl1.Tables.GetItem(10).Rows.Count - 1; i++)
{
if (this.textControl1.Tables.GetItem(10).Cells.GetItem(i, 1).Text.StartsWith("主诉"))
{
row = i;
break;
}
}
this.textControl1.Selection.Length = this.textControl1.Tables.GetItem(10).Cells.GetItem(row, 1).Text.Length
- position;
this.textControl1.Selection.Text = "替换";
} 问题解决非常感谢! 不客气,应该的~ 回复 3楼gw0506的帖子
你写的代码是TX.Text.Control.ActiveX吗?感觉有些属性好象没有你写的那样?
SelStart与SectionStart,selLength与SectionLength有什么区别? 不是,我写的是TX for WinForms。
SelStart是selection.Start,不是sectionstart。 回复 7楼gw0506的帖子
如果是TX.Text.Control.ActiveX该怎么写呢? 一样的思路,你查一下文档吧。
页:
[1]