|
하안인 님이 쓰신 글 :
: 다시 한번더 올립니다.
:
: 워드에 표를 그리고 값을 대입하려고 합니다.
:
: 메크로 기능을 이용하여 비베소스는 구했는데
: 이것을 빌더로 어떻게 바꿔야 하는지를 몰라서.
:
: ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
: 4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
: wdAutoFitFixed
: Selection.TypeText Text:="안녕"
: Selection.MoveRight Unit:=wdCharacter, Count:=1
: Selection.TypeText Text:="하하"
: Selection.MoveRight Unit:=wdCharacter, Count:=1
:
: 위 소스를 빌더로 바꾸려면 어떻게 해야 하나요.
:
: WordDocument->Tables->Add( 첫번째 인자의 Range값을 어떻게 주어야 하는지....);
:
: 그리고 빌더에서는 인자가 맨끝에 하나더 있더라구요 prop 인가 ..
:
: 위소스를 빌더로 바꿔주시면 안될까요. 급한데..
: 아무리 찾아도 없네요.
컴포넌트 팔레트의 Office2K 탭의 TWordApplication 과 TWordDocument를 오늘에야 사용해보았는데요
여러 군데에서 지금 당장으로서는 제가 해결할 수 없는 오류가 발생하여 전체 예제는 보여드릴 수 없습니다.
다만, Table 추가시 첫번째 인자에 WordDocument->Range(EmptyParam,EmptyParam)를 지정하면 일단 테이블이 추가되기는 하네요.
WordDocument1->Tables->Add(WordDocument1->Range(EmptyParam,EmptyParam),2,4,OleVariant(wdWord9TableBehavior),OleVariant(wdAutoFitFixed));
OleVariant unit2move(wdCell) ,count2move(1);
WordApplication1->Options->ReplaceSelection=True;
WordApplication1->Selection->TypeText(WideString("내용 1").c_bstr());
WordApplication1->Selection->MoveRight(unit2move,count2move);
WordApplication1->Selection->TypeText(WideString("내용 2").c_bstr());
//WordApplication1->Selection->MoveRight(unit2move,count2move);
OleVariant filename(L"TestWordDoc.doc");
WordDocument1->SaveAs(filename,OleVariant(wdFormatDocument),OleVariant(False));
한편, 지금까지 다른 질문에 대한 답변에서 제가 보여드린 방식으로는 아래와 같이 하면 오류 없이 잘 됩니다.
Variant wordApp, wordDocuments, wordDocument,wordSelection,wordRange;
wordApp = Variant::CreateObject("Word.Application");
wordDocuments = wordApp.OlePropertyGet("Documents");
// wordDocument = wordDocuments.OleFunction("Open","??");
wordDocument = wordDocuments.OleFunction("Add",Variant::NoParam(),Variant::NoParam(),wdNewBlankDocument,Variant::NoParam());
wordSelection = wordApp.OlePropertyGet("Selection");
wordRange = wordSelection.OlePropertyGet("Range");
wordDocument.OlePropertyGet("Tables").OleFunction("Add",wordRange,2,4,wdWord9TableBehavior,wdAutoFitFixed);
wordSelection.OleFunction("TypeText", "안녕");
wordSelection.OleFunction("MoveRight", wdCharacter, 1);
wordSelection.OleFunction("TypeText","하하");
wordSelection.OleFunction("MoveRight", wdCharacter, 1);
|