zoukankan      html  css  js  c++  java
  • 编辑word中文本框的内容

    编辑word中文本框的内容

    先引入word的com组件,添加这个命名空间using System.Reflection; // For Missing.Value and BindingFlags
    复制下面的代码既可直接操作编辑word中textbox的内容




    OpenFileDialog op = new OpenFileDialog();
                if (op.ShowDialog() == DialogResult.OK)
                {
                    Microsoft.Office.Interop.Word.ApplicationClass myWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                    Microsoft.Office.Interop.Word.Document  myWordDoc = new Microsoft.Office.Interop.Word.Document();
                    myWordApp.Visible = true;
                    Object filename = op.FileName;
                    Object ConfirmConversions = false;
                    Object ReadOnly = true;
                    Object AddToRecentFiles = false;

                    Object PasswordDocument = System.Type.Missing;
                    Object PasswordTemplate = System.Type.Missing;
                    Object Revert = System.Type.Missing;
                    Object WritePasswordDocument = System.Type.Missing;
                    Object WritePasswordTemplate = System.Type.Missing;
                    Object Format = System.Type.Missing;
                    Object Encoding = System.Type.Missing;
                    Object Visible = System.Type.Missing;
                    Object OpenAndRepair = System.Type.Missing;
                    Object DocumentDirection = System.Type.Missing;
                    Object NoEncodingDialog = System.Type.Missing;
                    Object XMLTransform = System.Type.Missing;

                    myWordDoc = myWordApp.Documents.Open(ref filename, ref ConfirmConversions,
                    ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
                    ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
                    ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection,
                    ref NoEncodingDialog, ref XMLTransform);

                    object line = 1;
                    int i = 1;
                    bool yn = true;
                    do
                    {
                        try
                        {
                            line = i;
                            string sss = this.myWordApp.ActiveDocument.Shapes.Range(ref line).TextFrame.TextRange.Text;
                            string te ="["+ i.ToString()+"]"+sss;
                            this.myWordApp.ActiveDocument.Shapes.Range(ref line).TextFrame.TextRange.Text = te;
                             i++;
                        }
                        catch
                        {
                            yn = false;
                        }
                    }
                    while (yn);
                    //关闭WordApp组件对象           
                    Object SaveChanges = false;
                    Object OriginalFormat = System.Type.Missing;
                    Object RouteDocument = System.Type.Missing;
                    myWordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
                }

  • 相关阅读:
    注册接口
    配置node 的路由
    mongoose 与 mylab 的使用 (1)
    PHP中PDO错误/异常(PDOException)处理
    如何使用PDO查询Mysql来避免SQL注入风险?ThinkPHP 3.1中的SQL注入漏洞分析!
    PHP5中PDO的入门教程
    PHP文件夹文件拷贝/复制函数 dir_copy($src = '', $dst = '')
    php将图片以二进制保存到mysql数据库并显示
    php 显示sqlserver二进制图片
    XML文档的PHP程序查询代码
  • 原文地址:https://www.cnblogs.com/dreign/p/420293.html
Copyright © 2011-2022 走看看