Solved

Process Word document in c++

Posted on 2006-11-30
2
926 Views
Last Modified: 2008-03-04
Perhaps someone could assist in converting the following VB code to c++.

Thanks.

Dim app as Object

Public Function convertHtmlCopyResultsToClipboard(fileName As String) As Boolean
   
    Dim doc As Word.Document
    Dim stl As Word.Style
    Dim tbl As Word.Table
   
    If app Is Nothing Then
        Set app = CreateObject("Word.Application")
    End If
    app.Visible = False
    app.Documents.Open fileName ' this is an html file if that matters
    Set doc = app.ActiveDocument
     
    For Each tbl In doc.Tables
        tbl.ConvertToText
    Next

    doc.Content.Copy
    doc.Close


 End Function
0
Comment
Question by:joex
2 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 18051653
Here are the steps (given for word 8 but you can update as necessary for your version of word)

- Import msword8.tlb (or a suitable type library for microsoft word) or if you are using MFC Use the class wizard and select "Add class from Type Library" and select msword8.tlb.

The following steps are for the later approach.

- Class wizard should've added new classes to your solution like _Application, _Document etc.

COleVariant var;
((LPVARIANT)var)->vt = VT_ERROR;
((LPVARIANT)var)->scode = DISP_E_PARAMNOTFOUND;

_Application application;
if(!application.CreateDispatch(_T("word.application")))
{
      // error
}
application.SetVisible(FALSE);
Documents documents = application.GetDocuments();

COleVariant varName,varFormat;
varName = filename;
_Document document = documents.Open(varName ,var, var, var, var, var, var, var, var, var);

Tables tables = document.GetTables();
for(int i=0; i<tables.GetCount(); i++)
{
     Table table = tables.GetItem(i);
     table.ConvertToText(var);
}

and so on ...

Hope that helps!
0
 

Author Comment

by:joex
ID: 18055755
It helps, but there are all kinds of problems with interacting with desktop instances of word when a DLL is repeatedly used to modify html by removing its tables.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question