Word Document save as html

LgooLgoo Member Posts: 45
Hi,

i try to save a word document as html format. But how can i create a instance of "Microsoft.Officce.Interop.Word.WdSaveFormat"? I need this enum for the function:
WordDocument.SaveAs2();

Answers

  • nhsejthnhsejth Member, Microsoft Employee Posts: 34
    Create a DotNet instance of that type and pass it to SaveAs2.
    Paste the following snip into a text file and import as a codeunit, you can the copy the variable decl to your own object. The WdSaveFormat type is a simple enum tha tcan be handled with the normal DotNet support in AL. If you have top use more than a few office interop functions, I will strongly recommend to add a C# wrapper assembly that encapsulates the requried fucntions in an API that can be used in AL without adding the full parameter list.
    OBJECT Codeunit 50000 wdFormatHTML
    {
      OBJECT-PROPERTIES
      {
        Date=;
        Time=;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=VAR
                WdSaveFormat@1000 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.WdSaveFormat";
                WordDocument@1001 : DotNet "'Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.Microsoft.Office.Interop.Word.Document";
              BEGIN
                WdSaveFormat := WdSaveFormat.wdFormatHTML;
                //WordDocument.SaveAs2(
                //  ref System.Object FileName, ref System.Object FileFormat, ref System.Object LockComments,
                //  ref System.Object Password, ref System.Object AddToRecentFiles, ref System.Object WritePassword,
                //  ref System.Object ReadOnlyRecommended, ref System.Object EmbedTrueTypeFonts, ref System.Object SaveNativePictureFormat,
                //  ref System.Object SaveFormsData, ref System.Object SaveAsAOCELetter, ref System.Object Encoding,
                //  ref System.Object InsertLineBreaks, ref System.Object AllowSubstitutions, ref System.Object LineEnding,
                //  ref System.Object AddBiDiMarks, ref System.Object CompatibilityMode)
              END;
    
      }
      CODE
      {
    
        BEGIN
        END.
      }
    }
    
    
    _________________
    Niels-Henrik Sejthen
    Senior Software Developer
    Microsoft Dynamics NAV

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
Sign In or Register to comment.