huyu1681 发表于 2015-1-12 17:22:00

回复 19楼iceman的帖子

是不是得用坐标,找位置添加??

huyu1681 发表于 2015-1-12 18:01:00

回复 19楼iceman的帖子

添加 MergeField,用坐标定位添加MergeField 的代码。。能请教下吗??谢谢了:D

iceman 发表于 2015-1-13 11:13:00

回复 22楼huyu1681的帖子

测试代码如下:

public tx_linkage()
      {
            InitializeComponent();
      }

      TXTextControl.ApplicationFieldCollection afc;

      private void Form1_Load(object sender, EventArgs e)
      {
            TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings();
            ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord;
            ls.ApplicationFieldTypeNames = new string[] { "MERGEFIELD" };
            this.textControl1.Load(AppDomain.CurrentDomain.BaseDirectory + "\\resource\\病历模板的格式-入院录.doc", TXTextControl.StreamType.MSWord, ls);
            afc = this.textControl1.ApplicationFields;

            GetMergeField(this.textControl1.ApplicationFields.GetItem(0));
            BindData();

      }
      string text;
      int start = 0;
      int length= 0;
      private void GetMergeField(ApplicationField applicationField)
      {
            start = applicationField.Start;
            length = applicationField.Length;
            text = applicationField.Text;

      }

      private void AddMergeField()
      {
            MergeField mergeField = new MergeField();
            mergeField.Text = text;
            mergeField.ApplicationField.ShowActivated = true;
            mergeField.ApplicationField.DoubledInputPosition = true;

            textControl1.Focus();
            textControl1.Selection.Start = start-1;
            textControl1.ApplicationFields.Add(mergeField.ApplicationField);
      }

      private void BindData()
      {
            //连接数据库
            string dbconStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=resource\\txdb.mdb";
            OleDbConnection dbcon = new OleDbConnection(dbconStr);
            if (dbcon.State == ConnectionState.Closed)
            {
                dbcon.Open();
            }

            DataTable dt = new DataTable();
            OleDbDataAdapter dbAdapter = new OleDbDataAdapter("select* from persons", dbcon);

            dbAdapter.Fill(dt);
            mailMerge1.TextComponent = this.textControl1;
            mailMerge1.SearchPath = "";
            mailMerge1.TemplateFile = AppDomain.CurrentDomain.BaseDirectory + "\\resource\\病历模板的格式-入院录.doc";
            mailMerge1.Merge(dt, true);
            
            AddMergeField();

      }


我这里默认需要添加 mergefield 为,需要再做些操作,比如先获取所有字段信息进行对比等。

huyu1681 发表于 2015-1-13 15:13:00

回复 23楼iceman的帖子

你好,哪句代码是控制第几个mailMerge。。是GetMergeField(this.textControl1.ApplicationFields.GetItem(0));
吗??如果改成
GetMergeField(this.textControl1.ApplicationFields.GetItem(1));
就有添加--职业这个了吗?谢谢

iceman 发表于 2015-1-13 15:16:00

回复 24楼huyu1681的帖子

是的,你理解的正确。

huyu1681 发表于 2015-1-14 09:30:00

回复 25楼iceman的帖子

那怎么获取那个里面的位置。谢谢,能给段循环代码吗?
:jy74a:

iceman 发表于 2015-1-14 11:30:00

回复 26楼huyu1681的帖子

以下这段代码就是获取 Field 的信息的:

string text;

      int start = 0;

      int length= 0;

      private void GetMergeField(ApplicationField applicationField)

      {
            start = applicationField.Start;
            length = applicationField.Length;
            text = applicationField.Text;
      }


循环你的意思是有多个 Field 无法对应吗?那就重复调用这个方法,传递不同的ApplicationField 参数就行了。

huyu1681 发表于 2015-1-14 13:36:00

回复 25楼iceman的帖子

你好,我添加了2个mailMerge,,用GetMergeField(this.textControl1.ApplicationFields.GetItem(0));
能获取到第一个mailMerge的信息,能添加。。科室获取第2的时候,代码是GetMergeField(this.textControl1.ApplicationFields.GetItem(1));
就直接报错了。。获取不到,请问GetItem(1)。。里面int型的数字,是什么意思。怎么控制。谢谢

huyu1681 发表于 2015-1-14 13:41:00

回复 27楼iceman的帖子

我是获取不到第2个Field 的信息。GetMergeField(this.textControl1.ApplicationFields.GetItem(0));
这句代码是获取Field信息的吧。。我的是意思添加多个
Field。。但是只能获取到第一个添加的,其他的获取不到。。如果把0改1.就报错了。

iceman 发表于 2015-1-14 17:40:00

回复 29楼huyu1681的帖子

亲,能否通过论坛短消息留一个联系电话,我们电话沟通。谢谢
页: 1 2 [3] 4 5
查看完整版本: 新建TextField 添加保存文档后,在读取就失去样式了,鼠标放在那的小手没了