Word integration with dotnet variables

ACAE
Member Posts: 52
Hello,
I'm updating our current word integration so the automations are replaced by dotnet variables (for NAV 2013). This is basically the normal word integration of NAV, but we added some extra functions to insert pictures, tables, ...
This is now a real issue to update due to the fact that all parameters must be passed, even those that are optional.
I already found a topic suggesting to create a 'missing class' (viewtopic.php?f=32&t=51875&hilit=word+interop+.net), but this doesn't work anymore in NAV 2013:
- if I use Missing.MissingParamter I get the error 'Internal Compiler Error. Error Code = 00000022'
- if I use Missing.MissingValue I get the error 'A variable was expected'.
I also tried to pass a variable that is defined but not filled up, but then I get a type mismatch error. It concerns the word function "WordRange.InlineShapes.AddPicture" where the 4th parameter is a 'word range' variable, but if you pass a word range you get a type mismatch error. So I am kind of stuck here.
Does anyone know a solution for this ? I also tried to create a C# class but I also can't pass the range variable (type mismatch).
Kind regards,
Andy
I'm updating our current word integration so the automations are replaced by dotnet variables (for NAV 2013). This is basically the normal word integration of NAV, but we added some extra functions to insert pictures, tables, ...
This is now a real issue to update due to the fact that all parameters must be passed, even those that are optional.
I already found a topic suggesting to create a 'missing class' (viewtopic.php?f=32&t=51875&hilit=word+interop+.net), but this doesn't work anymore in NAV 2013:
- if I use Missing.MissingParamter I get the error 'Internal Compiler Error. Error Code = 00000022'
- if I use Missing.MissingValue I get the error 'A variable was expected'.
I also tried to pass a variable that is defined but not filled up, but then I get a type mismatch error. It concerns the word function "WordRange.InlineShapes.AddPicture" where the 4th parameter is a 'word range' variable, but if you pass a word range you get a type mismatch error. So I am kind of stuck here.
Does anyone know a solution for this ? I also tried to create a C# class but I also can't pass the range variable (type mismatch).
Kind regards,
Andy
0
Comments
-
Hello,
I finally solved this by creating a C# class and passing the whole word document to insert a picture.
Perhaps a tip for those who also struggle with this: if you add a reference in Visual studio to Microsoft.Office.Interop.Word (or Excel, Access, ...) set "Specific version" to false. This has cost me a few hours to find out but it solved my type mismatch error :thumbsup:0 -
Would you mind sharing the source of this class + the calling c/al code. Just to understand how things work..
Of course you can remove some parts which should be protected.0 -
No problem, this is the code in C#:
public bool InsertPictureInWordDoc(Microsoft.Office.Interop.Word.Document pnetWordDoc, string ptMergeField, string ptFileName)
{
Microsoft.Office.Interop.Word.Range lnetRange = null;
Microsoft.Office.Interop.Word.Range lnetRange2;
Microsoft.Office.Interop.Word.InlineShape lnetShape;
var r = pnetWordDoc.Content;
lnetRange = pnetWordDoc.Content;
ptFileName = ptFileName.Trim();
if (ptFileName == "")
lnetRange.Delete();
else
if (lnetRange.Find.Execute(ptMergeField))
{
lnetRange2 = lnetRange;
lnetRange.Delete();
lnetShape = pnetWordDoc.InlineShapes.AddPicture(ptFileName, Type.Missing, Type.Missing, lnetRange2);
}
}
return true;
}
And in C/AL:
lnetNaviTransOfficeHelper.InsertPictureInWordDoc( pnetWordDocument, precMergeFields."Merge Field", ltxtPicture);
where pnetWordDocument is a dotnet variable of type Microsoft.Office.Interop.Word.Document.'Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'0 -
Thanks.
1.
So you are creating a reference in c/al to a word document
2.
Transfer a reference for this object to a c# class
3.
do things with it
4.
and back.
Note:
It seems like you are transferring the whole object but actually you are only sending an address to an object (word). So it must be fast and will take up only the extra class in memory.0 -
Hi,
Yes that is about it. I used the NAV wordhelper to open the document and merge it, but in this routine it isn't possible to add pictures or tables.
There are just some things to keep in mind in C#
- Microsoft.Office.Interop.Word reference with 'specific version' = false
- Do not pass the word document as 'ref' (or 'out') as this causes a NAV crash
Otherwise it is pretty simple
Andy0 -
This will only work in NAV2013 ?
Did you needed to do some special tricks to get it working in NAV 2009 RTC ?0 -
I suppose it should work in 2009, but in that version we used automations. For 2013 we try to replace all these with dotnet variables, but some issues need to be solved in VS0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions