yangjianlang 发表于 2016-2-18 16:34:00

求解替换表格列内容



想把表格中主诉、现病史这些field后面的字符内容(普通字符,不是field)用程序替换成需要的文字,请版主指导一下,谢谢!

gw0506 发表于 2016-2-18 18:39:00

基本想法就是找到关键字,然后确定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 = "替换";

gw0506 发表于 2016-2-19 12:33:00

修改后,可以使用了。
      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 = "替换";
      }

yangjianlang 发表于 2016-2-25 01:19:00

问题解决非常感谢!

gw0506 发表于 2016-2-25 15:33:00

不客气,应该的~

yangjianlang 发表于 2016-2-26 23:28:00

回复 3楼gw0506的帖子

你写的代码是TX.Text.Control.ActiveX吗?感觉有些属性好象没有你写的那样?

SelStart与SectionStart,selLength与SectionLength有什么区别?

gw0506 发表于 2016-2-29 12:08:00

不是,我写的是TX for WinForms。
SelStart是selection.Start,不是sectionstart。

yangjianlang 发表于 2016-3-3 00:16:00

回复 7楼gw0506的帖子

如果是TX.Text.Control.ActiveX该怎么写呢?

gw0506 发表于 2016-3-3 15:10:00

一样的思路,你查一下文档吧。
页: [1]
查看完整版本: 求解替换表格列内容