スポンサーリンク
前回は書き出す方をやったので、今回は読み込む方をやる。
#include "pch.h" using namespace System; int main(array<::System::String ^> ^args) { Microsoft::Office::Interop::Word::Application^ word = gcnew Microsoft::Office::Interop::Word::Application(); word->Visible = false; Object^ oMissing = ::System::Reflection::Missing::Value; Object^ oTrue = true; Object^ oFalse = false; // Word文書を開く System::String^ fname = "C:\\test\\out.docx"; Microsoft::Office::Interop::Word::Document^ document = word->Documents->Open(fname, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); for each(Microsoft::Office::Interop::Word::Paragraph^ par in document->Paragraphs) { Microsoft::Office::Interop::Word::Range^ ran = par->Range; System::String^ str = ran->Text; System::Console::WriteLine(str); } // 文書を閉じる ((Microsoft::Office::Interop::Word::_Document^)(document))->Close(oFalse, oMissing, oMissing); ((Microsoft::Office::Interop::Word::_Application^)word)->Quit(oMissing, oMissing, oMissing); return 0; }