Solved

Process Word document in c++

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  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 …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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