0

選択したページを Word DocumentA から別の Word DocumentB に移動する必要があります。したがって、最終的に DocumentB には独自のコンテンツと、DocumentB の選択されたページに挿入された DocumentA から選択されたページが含まれている必要があります。DocumentB のページ番号は、プロパティで設定します。

これは、DocumentA のコンテンツを DocumentB に追加するために使用しているコードです。

  object missing = System.Reflection.Missing.Value;
  Word._Application wordApp = new Word.Application();
  Word._Document aDoc = new Word.Document();

  try
  {

     wordApp.Visible = false;
     object readOnly = false;
     object isVisible = false;

     aDoc = wordApp.Documents.Open(ref fPath1, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

     Word.Selection selection = wordApp.Selection;
     selection.InsertFile(fPath2, ref missing, ref missing, ref missing, ref missing);
     aDoc.Save();
     wordApp.Quit(ref missing, ref missing, ref missing);
   }
        catch(Exception ex)
        {
            throw new Exception(ex.Message);
        }
        finally
        {
            wordApp = null;
            aDoc = null;
        }

ただし、「selection.InsertFile...」行で「オブジェクト参照がオブジェクトのインスタンスに設定されていません」という例外が引き続き発生します。

ここで何がうまくいかないのですか?

DocumentA のページ 2 のコンテンツを DocumentB のページ 3 に挿入するにはどうすればよいですか?

御時間ありがとうございます。

4

2 に答える 2

0

Word でテキストを選択してから実行していますか? Word でテキストが選択されていない場合、その例外が発生すると思います。

于 2010-06-01T15:11:20.553 に答える
0

私はVisioの相互運用を少し行ってきましたが、選択は配列であるため、wordApp.Selectionに何も追加していない可能性があります.

于 2010-06-01T15:18:10.450 に答える