ninja_aya 发表于 2015-9-14 17:26:00

两个tx文件部分内容合并

你好,请问下我有两份tx,比如a.tx和b.tx其中两个tx各自有多个Section,我现在想将b.tx中的某几个Section原封不动的复制到a.tx包括里面的各种域和页眉页脚等。请问如何实现。

iceman 发表于 2015-9-15 12:24:00

回复 1楼ninja_aya的帖子

问题请参考附件Demo:


使用代码选中 Section后,直接粘贴到另一个 tx 中即可。

ninja_aya 发表于 2015-9-15 14:30:00

我是想用代码实现

ninja_aya 发表于 2015-9-15 14:53:00

你给的示例代码没有任何效果。

iceman 发表于 2015-9-15 16:39:00

回复 4楼ninja_aya的帖子

抱歉,少些了一句 Copy 代码,请替换相应方法如下:

private void Form1_Load(object sender, EventArgs e)
      {
            this.textControl1.Load("..\\..\\testsection.tx", TXTextControl.StreamType.InternalUnicodeFormat);

      }

      private void copyToolStripMenuItem_Click(object sender, EventArgs e)
      {
            foreach (TXTextControl.Section s in this.textControl1.Sections)
            {
                this.textControl1.Select(s.Start, s.Length);
                this.textControl1.Copy();
            }
      }

      private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
      {
            this.textControl2.Focus();
            this.textControl2.Text = "";
             this.textControl2.Paste();
      }

ninja_aya 发表于 2015-9-16 09:30:00

你给我的这个程序有些问题,我这边修改了下,你帮我看下,为什么出现下面这些情况。
合成按钮:我选择了你那个tx文件的第一个section,但是选中后复制过去的并不是第一个section内容。

合成2按钮是我这边的一个tx,我是想把第五个section的内容复制后,合成到另一个tx中的第六个section位置,合并后保存成3.tx,但是打开3.tx没有任何作用。


iceman 发表于 2015-9-16 14:26:00

回复 6楼ninja_aya的帖子

无界面操作文档需要使用 servertextcontrol,请查看下面代码是否符合您的需求:

      private void fToolStripMenuItem_Click(object sender, EventArgs e)
      {
            TXTextControl.ServerTextControl svt1 = new TXTextControl.ServerTextControl();
            svt1.Create();
            svt1.Load("..\\..\\1.tx", TXTextControl.StreamType.InternalUnicodeFormat);

            TXTextControl.ServerTextControl svt2 = new TXTextControl.ServerTextControl();
            svt2.Create();
            svt2.Load("..\\..\\1.tx", TXTextControl.StreamType.InternalUnicodeFormat);

            TXTextControl.Section s = svt1.Sections;
            s.Select();
            svt1.Selection.Save("..\\..\\test.tx", TXTextControl.StreamType.InternalUnicodeFormat);

            svt2.Selection.Start = svt2.Sections.Start;
            svt2.Selection.Length = 0;
            svt2.Selection.Load("..\\..\\test.tx", TXTextControl.StreamType.InternalUnicodeFormat);

            svt2.Save("..\\..\\4.tx", TXTextControl.StreamType.InternalUnicodeFormat);

            textControl2.Load("..\\..\\4.tx", TXTextControl.StreamType.InternalUnicodeFormat);
      }


直接覆盖 fToolStripMenuItem_Click 事件即可。

ninja_aya 发表于 2015-9-17 09:12:00

The following control could not be licensed: TXTextControl.ServerTextControl


我这边购买的不能使用ServerTextControl吗?

ninja_aya 发表于 2015-9-17 09:15:00

哦,好了。

iceman 发表于 2015-9-17 11:18:00

回复 9楼ninja_aya的帖子

好的,请问效果是否满足您的需求?
页: [1] 2
查看完整版本: 两个tx文件部分内容合并