Solved

Process Word document in c++

Posted on 2006-11-30
2
921 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 73
Embarcadero C++ Builder XE2 TDateTime 8 70
FMX enumerated colours 2 99
What is sub-make ? 2 60
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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