Hi, I’m hoping someone can help me out here, a customer(using Navision 3.60) wants to create a MS Word document from a button on a customer card which basically shows all items bought by the customer accompanied by a jpeg for each item(they don’t want to convert to bitmaps). I have managed to open Word and show the Item No. etc as well as the accompanying jpeg, however the report should display 2 columns and this is where the problem lies, how do I position the text & jpegs to display in 2 columns? The code so far is below, any help is much appreciated - thanks. CLEAR(wdrng); CLEAR(wddoc); CLEAR(wdapp); CLEAR(wdInlineShape); CREATE(wdapp); wddoc := wdapp.Documents.Add; wdapp.ActiveDocument.Fields.Update; ch := 13; wdrng := wdapp.ActiveDocument.Range; IF FIND(’-’) THEN REPEAT CLEAR(Pic); ItemRec.SETRANGE(“No.”,“Item No.”); IF ItemRec.FIND(’-’) THEN IF ItemRec.“Image Link 2” <> ‘’ THEN BEGIN Pic := ItemRec.“Image Link 2”; wdrng.InsertBefore(FORMAT(ch)); wdInlineShape := wdapp.ActiveDocument.InlineShapes.AddPicture(Pic); wdrng.InsertBefore(FORMAT(ch)); wdrng.InsertBefore(ItemRec.“Description 2”); wdrng.InsertBefore(FORMAT(ch)); wdrng.InsertBefore(ItemRec.Description); wdrng.InsertBefore(FORMAT(ch)); wdrng.InsertBefore(ItemRec.“No.”); wdrng.InsertBefore(FORMAT(ch)); END; UNTIL NEXT = 0; wdapp.Visible := TRUE; CLEAR(wdInlineShape); CLEAR(wdrng); CLEAR(wddoc); CLEAR(wdapp);
Mike, Why don’t you create a template document with a 2 column table. Then fill in the relevant row and column. Then save the document using Save As (so you don’t overwrite the template. Hope this helps.
You can find out the Word automation interface the easiest way by recording a macro in Word en then have a look at the code that is generated. Many functions used in the macro can be found in the word automation interface as well. So start recording a macro, build the disered layout and have a look at the code that is generated.
Thanks for your help guys, I’ve now modified the code to open a Word template with a table consisting of 2 columns and 3 rows, but how do I place the text and jpeg into each cell? This is becoming a real pain - I need help, once again thanks for any help. P.S. - I tried using the macro recorder, but couldn’t tab out of each cell while using it, which defeats the object[:(]
Right, I finally managed to get the pictures into the correct cells and also resize them, however I cannot get them to keep their ‘aspect ratio’ when resizing, the code below is what I’m using, if anyone has successfully done this please let me know - cheers! - Mike IF Pic <> ‘’ THEN BEGIN wdInlineShape := Selection.InlineShapes.AddPicture(Pic); //wdInlineShape.LockAspectRatio(-1); //This line doesn’t work wdInlineShape.Height(140); wdInlineShape.Width(150); Selection.TypeParagraph; Selection.TypeParagraph; Selection.Font.Name := ‘Tahoma’; Selection.Font.Size := 10; Selection.TypeText(ItemRec.“No.”); Selection.TypeParagraph; Selection.TypeText(ItemRec.Description); Selection.TypeParagraph; Selection.TypeParagraph; Selection.MoveRight(wdcell,y); END; UNTIL NEXT = 0;
Hello Mike, If your only problem is showing JPG’s you might want to take a look at Embedded Controls in the download section of www.mibuso.com The PictureViewer can show JPG on navision forms and autofit the aspect ration as well. Then you don’t have to bother with MS Word automation. Regards, Jan-Pieter
Hi Jan-Pieter, Thanks for your reply, but I can get the pictures to display and everything else works fine I just need to be able to resize the pictures whilst keeping the aspect ratio, by all accounts I thought it would be a simple task of:- ‘selection.inlineshapes.LockAspectRatio(-1);’,this is the CAL equivalent to VB’s:- ‘selection.inlineshapes(1).LockAspectRatio = msoTrue’. Surely someone on this forum has successfully achieved this already.