Solved

Process Word document in c++

Posted on 2006-11-30
2
933 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

728 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