Solved

Process Word document in c++

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now