OLE Automation with Delphi and MS Word

I'm working with Delphi for a while now, but it's the first time that I need to export in Word some data taken from a sqlite database.

With SQLite there are no problems, everything works as it should. With Word, also because of the lack of good part of documentation, I'm currently having troubles, in particular, in the moment when i go to split a cell of a table, depending on the number of occurrences found with a SQLite query (1 occurrence = do nothing, 2 occurrences = split the cell into two rows, 15 occurrences = split the cell into 15 rows and so on).

 When i create the table in Word, everything works fine, and so does the first column popupation with the database found occurrences.

But when I ask him to split the cell, the next iteration that parses all results found by the query raises an Ole Error "The requested member of the collection does not exist".
Particularly, without the code used to split the cells, everything is fine, the program finishes to elaborate all iterations based on the query results and the process concludes succesfully.
 WITH the splitting code, only the first iteration completes and when the second begins, the Ole Error is raised.

I believe that there is something word doesn't like with the cursor position but the same cursor, controlling the parsing with  WordApp.Visible := True stays in the same place, at least visually (i don't know if word places the visual cursor in one place and a "virtual" one, in another)

This is my code...does someone understand where am I wrong?

adm_tbl := db.GetTable('SELECT * FROM rdb_administration_names ORDER BY administrations_order;');
  for l := 1 to adm_tbl.Count do
    WordApp.Selection.ParagraphFormat.Alignment := 1;
    WordApp.Selection.Font.Color := $0000FF;
    WordApp.Selection.Font.Size := 14;
    comp_tbl := db.GetTable('SELECT * FROM rdb_compartments WHERE administration_hash = "' + adm_tbl.FieldAsString(adm_tbl.FieldIndex['administration_hash']) + '" ORDER BY compartments_order;');
    for m := 1 to comp_tbl.Count do
      WordApp.Selection.ParagraphFormat.Alignment := 0;
      WordApp.Selection.Font.Color := $0000C0;
      WordApp.Selection.Font.Size := 10;
      WordApp.Selection.TypeText('COMPARTIMENTO DI ' + comp_tbl.FieldAsString(comp_tbl.FieldIndex['compartment_name']));
      WordApp.Selection.Font.Color := $0000C0;
      WordApp.Selection.Font.Size := 8;
      WordApp.Selection.Font.Bold := True;
      plant_tbl := db.GetTable('SELECT * FROM rdb_plants INNER JOIN rdb_plant_names ON rdb_plants.plant_hash = rdb_plant_names.plant_hash AND rdb_plants.compartment_hash = "' + comp_tbl.FieldAsString(comp_tbl.FieldIndex['compartment_hash']) + '" ORDER BY rdb_plant_names.plant_name');
      WordApp.Selection.Tables.Item(1).Cell(1, 1).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 1).Range.Text := 'Stazione';
      WordApp.Selection.Tables.Item(1).Cell(1, 2).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 2).Range.Text := 'Apparati';
      WordApp.Selection.Tables.Item(1).Cell(1, 3).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 3).Range.Text := 'Att.';
      WordApp.Selection.Tables.Item(1).Cell(1, 4).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 4).Range.Text := 'Sop.';
      WordApp.Selection.Tables.Item(1).Cell(1, 5).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 5).Range.Text := 'Segnalamento';
      WordApp.Selection.Tables.Item(1).Cell(1, 6).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 6).Range.Text := 'PS';
      WordApp.Selection.Tables.Item(1).Cell(1, 7).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 7).Range.Text := 'TC';
      WordApp.Selection.Tables.Item(1).Cell(1, 8).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 8).Range.Text := 'PL';
      WordApp.Selection.Tables.Item(1).Cell(1, 9).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 9).Range.Text := 'SCmt';
      WordApp.Selection.Tables.Item(1).Cell(1, 10).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 10).Range.Text := 'TE';
      WordApp.Selection.Tables.Item(1).Cell(1, 11).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 11).Range.Text := 'TLc';
      WordApp.Selection.Tables.Item(1).Cell(1, 12).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 12).Range.Text := 'M';
      WordApp.Selection.Tables.Item(1).Cell(1, 13).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 13).Range.Text := 'ID';
      WordApp.Selection.Tables.Item(1).Cell(1, 14).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 14).Range.Text := 'Blocco';
      WordApp.Selection.Tables.Item(1).Cell(1, 15).Range.Paragraphs.Alignment := 1;
      WordApp.Selection.Tables.Item(1).Cell(1, 15).Range.Text := 'Note';
      pb.Max := plant_tbl.Count;
      for n := 1 to plant_tbl.Count do
        WordApp.Selection.Tables.Item(1).Cell(n+1, 1).Range.Font.Color := $000000; <--- ERRORE QUI ALLA SECONDA ITERAZIONE
        WordApp.Selection.Tables.Item(1).Cell(n+1, 1).Range.Font.Size := 8;
        WordApp.Selection.Tables.Item(1).Cell(n+1, 1).Range.Font.Bold := True;
        WordApp.Selection.Tables.Item(1).Cell(n+1, 1).Range.Text := plant_tbl.FieldAsString(plant_tbl.FieldIndex['plant_name']);
        pb.Position := n;
        StatusBar.Panels[0].Text := 'Exporting ' + adm_tbl.FieldAsString(adm_tbl.FieldIndex['administration_name']) + '->' + comp_tbl.FieldAsString(comp_tbl.FieldIndex['compartment_name']) + '->' + plant_tbl.FieldAsString(plant_tbl.FieldIndex['plant_name']) + ' - ' + IntToStr(n) + ' of ' + IntToStr(plant_tbl.Count);
        unit_tbl := db.GetTable('SELECT * FROM rdb_controlunits WHERE plant_hash = "' + plant_tbl.FieldAsString(plant_tbl.FieldIndex['plant_hash']) + '" ORDER BY controlunit_start;');
        for int := 2 to 15 do
          WordApp.Selection.Tables.Item(1).Cell(n+1, int).Split(unit_tbl.Count, 1);
2/18/2015 6:24:14 PM
embarcadero.delphi.ole 598 articles. 1 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 22
Get it on Google Play
Get it on Apple App Store


Similar Artilces:

OLE Automation with Delphi and MS Word [Edit]
Hi, I'm working with Delphi for a while now, but it's the first time that I need to export in Word some data taken from a sqlite database. With SQLite there are no problems, everything works as it should. With Word, also because of the lack of good part of documentation, I'm currently having troubles, in particular, in the moment when i go to split a cell of a table, depending on the number of occurrences found with a SQLite query (1 occurrence = do nothing, 2 occurrences = split the cell into two rows, 15 occurrences = split the cell into 15 rows and so on). When i create ...

MS-Word & Powerpoint automation, using OLE automation [Edit]
Hello, Here is what I need to do, from my Delphi application : starting from a MS-Word document, create a PPT presentation simply made of a series of embedded MS-Word objects. There would be 1 slide for each page of the source document (assuming same page size & orientation on both sides). This requires to control both a WordApplication and a PowerpointApplication in parallel, and proceed basically as follows : - in Word, open the source file - In Powerpoint, create a new presentation - For each page of the Word doc, |- in Word, select from start to end of current page, then &quo...

OLE Automation and MS Word
In evaluating the feasibility of using PB for an application that will use OLE Automation to interface with MS Word, I wrote some exploratory code to determine how efective PB would be as a 'driver' for OLE automation. I have a really simple test application that contains the following snippet of code: integer li_count string ls_bookmark li_count = iole_worddoc.CountBookmarks ls_bookmark = iole_worddoc.bookmarkname(1) ls_bookmark = iole_worddoc.bookmarkname(2) The first line executes in less then 1/2 second. The second line take...

Delphi OLE automation inside a windows service
Hello: I have a simple question. I did a program (a service) with a timer: every 10 minutes, this service goes to a database, take records and sends informative mail to customers using Outlook with OLE automation. This program, as standalone program, works fine. But this program, converted as service, call Outlook and the service stop. Any ideas? The service code: procedure TDistriMail.ServiceExecute(Sender: TService); // the OnExecute service begin Timer1.Enabled := True; while not Terminated do ServiceThread.ProcessRequests(True);// wait for termination ...

Word ole: How to close MS word
I have ole control on the window and inset file using Ole_control.InsertFile(file_name) When I close the window I still see the word running in task manager. How do I close Word? How about looking at the Quit method? Katarina wrote: > I have ole control on the window and inset file using > Ole_control.InsertFile(file_name) > > When I close the window I still see the word running in task > manager. How do I close Word? ...

WORD OLE automation
The following code works perfectly with WORD6/Windows95/PB6, but does not work for WORD 97/NT. OLEObject lole_word string ls_mytext = "Trial text" li_rc = lole_word = CREATE OLEObject li_rc = lole_word.ConnectToNewObject("word.basic") // in NT WORD is opened INVISIBLY // It appears as a process in the Task Manager // li_rc = 0 li_rc = lole_word.FileNew("normal", 0) // Returns li_rc = NULL li_rc = lole_word.Insert(ls_mytext) // Not recognised by WORD97 li_rc = ...

WordPerfect: OLE automation through OLE control
OK, I connected to WordPerfect from PB6.5 by using OLEObject like: OLEObject ole_obj ole_obj= CREATE OLEobject li_rc=ole_obj.ConnectToNewObject ("WordPerfect.PerfectScript") ........ Now it accepts automation commands. But my goal is to start OLE automation through Object property of OLE control. Something like: ole_1.Activate(Offsite!) ole_obj=ole_1.Object.WordPerfect.PerfectScript ..... And that does not work though it does with Word. Does somebody know if it is possible at all to make OLE automation through OLE control and how to do that? Thanks ...

Word OLE automation
Would like to open word document using OLE after populating word using OLE Automation. The document should open up in print preview mode,and then using either VBA, or other code print or close from print preview. I want to supress all menus and commandbars from the word document. What code can i run from PB script to open in print preview and turn off menus and command bars, and put in two of my own command buttons. ...

OLE with MS Word
Hello all, Where can I find a list of Active X commands to control MS word. I'm trying to do: ole_1.Object.SaveAs("c:\test.doc") but "Save As HTML" instead. I would like to find a list of all the commands to carry out various functions. Thanks for reading! Rick This is all wriiten down in the Office developers books. Best place to search on the internet is http://msdn.microsoft.com HTH -- - Eric Aling [TeamSybase], Avalix Information Systems, The Netherlands Eric's Home & PB Site @ http://www.knoware.nl/users/cypr115 ...

Word OLE automation
I am about to embark on a PB 5.0 project that will require dynamic creation of documents for use with Word 97's mail merge capability. Being that this is my first time using OLE, as well as my first time programming Word, could anybody point me in the right direction (books, articles, web sites, etc.) to get me started? I've experimented a little with what I could find on Microsoft's and Sybase's sites, but I am looking for something more comprehensive. =============== Daniel Buki Software Developer Butte County (CA) Migrant Education cerkit@ncal.net In article...

OLE and MS Word
Hello, I'm looking for a simple application that creates a Word document (*.doc) and writes some text there without opening Word and then closes the connection to that OLE object... Thanks in advance... Have you tried looking at http://www.sybase.com/detail?id=47980 Just a hint. You can search the Sybase tech docs from http://www.sybase.com/support/techdocs Good luck, Terry [TeamSybase] and Sequel the techno-kitten On 3 Feb 2004 02:40:13 -0800, "Piotr Nadolny" <pnad@o2.pl> wrote: >I'm looking for a simple application that creates ...

OLE Word97 and ole objects vs ole controls
--------------50D299EA9D99A20C83E801AB Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit I am new to OLE automation. I'm trying to connect to a word97 document and filling forms fields with information. I'm trying to use the following code. I'm getting the following error in my log file: DateTime: 10/27/99 18:32:07 Title: System Error Message: Error Number 36. Error text = Name not found accessing external object property object. Window/Menu/Object = w_ole_test. Error Object/Control = cb_okay. Script = clicked. Line in Script = 22. ...

OLE Excel with Delphi 7
I am having troubles opening an Excel file with Delphi 7. I think I really need some Delphi specific examples or some help files. I am trying to follow examples in this forum and also seeing there is limited information in the help files. For example I try the following -- which seems to be working for others in the forum, I am assuming with later versions of Delphi Xapp1.Workbooks.open('...filename...'); //where file name is a valid name This gives me an error "Not enough actual parameters", One example I see has me try this: Xapp1.Workbooks.Open(&#...

OLE (MS-Word) Control
Hi everybody! I hope I say this all correctly, cause I have only about 6 months experience with PowerBuilder. I'm using version 6.5.1 of PowerBuilder... I have a datawindow where I have placed an OLE control (an MS-Word doc built in Office 97) in the detail band of the datawindow. The Word document is "linked" not "imbeded". The idea is to merge some addresses (Sybase columns) with the Word doc and print it. All of that works great, however once I print the datawindow (using PFC_PRINT), my mouse will appear normal, but clicking on anything, anywhere in...

Web resources about - OLE Automation with Delphi and MS Word - embarcadero.delphi.ole

Automation - Wikipedia, the free encyclopedia
For a hierarchical presentation of automation topics, see Outline of automation . For other uses, see Automation (disambiguation) . Automation ...

Automation World - Covering the field of industrial automation
AutomationWorld.com delivers content for the Automation Buying team, which includes Information Technology and Networking; Operations and Engineering; ...

Facebook Ads API Partner AdStage: Campaign Automation, $6.25M Series A Funding
AdStage , a Facebook ads API partner, announced Wednesday the launch of campaign automation — as well as a $6.25 million round of Series A funding. ...

Mind blown! Facebook’s f8 makes a mobile move into marketing automation
... Thus, you’ll need to build a mobile app (if you’re enterprise) or use an app-building platform (such as GroSocial). The marketing automation ...

Automation World (@automationworld)
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Automation World
Automation World is your link to the why and how of manufacturing automation. The purpose of this group is to connect manufacturing engineers, ...

Is home automation in your future or are you using it now?
Home automation gets touted by some as the future, but it's really the now. A seemingly endless list of products are on the market and they allow ...

Meet Microbot Push, a home automation gadget lazy people will love
A South Korean startup called Naran has come up with an incredibly clever way for users to control and automate any type of switch-oriented task ...

Robots Will Change World Beyond Recognition Says BoA; Automation Will Change Jobs More Than Kill Them ...
Robot Theory The battle of robot theory is on. Bank of America paints one picture and McKinsey another. Let's investigate both theories. Automation ...

Rockwell Automation Announces Mobility Co-Innovation with Microsoft
A new mobility co-innovation project by Rockwell Automation and Microsoft Corp. will be demonstrated at Automation Fair in Chicago Nov. 18 and ...

Resources last updated: 11/29/2015 6:29:41 PM