How to call style sheets through code

elwin68elwin68 Member Posts: 153
Hello,

For a customer I use style sheets so he can change the layout of the Word document himself.
This is working fine.

Normally a style sheet can be called by using the 3 icons in the icon bar.
Now I want to achieve the following:
- In a setup table the style sheet is specified which must be used.
- On the customer card a button is added which calles the style sheet through code.

Is it possible to achieve this?

With the standard buttons the function LaunchApp is used in codeunit 403 (Application Launch Management).
Parameter DataXML (Automation 'Microsoft XML, v6.0'.DOMDocument60) has the information of the record in the current form.

How can I convert a record variable to a automation of 'Microsoft XML, v6.0'.DOMDocument60?

Thanks in advance.

Answers

  • bangswitbangswit Member Posts: 265
    style sheet cannot send a parameter
  • ftbookumftbookum Member Posts: 10
    It can be done. But it isn't easy. I'll give you some 'raw' code. It's not working as it is, but it should give you a good start


    OBJECT Codeunit 99003 Style Sheet Merge To WORD
    {
    OBJECT-PROPERTIES
    {
    Date=18-01-11;
    Time=16:45:27;
    Modified=Yes;
    Version List=GREADD-4388;
    }
    PROPERTIES
    {
    OnRun=VAR
    codLabelID@1100502000 : ARRAY [4] OF Code[20];
    BEGIN
    codLabelID[1] := '00000007'; // Partij
    //codLabelID[2] := 'A00062'; // Leverancier
    //codLabelID[3] := '1002'; // Verkooporder
    //codLabelID[4] := 'TEST'; // Label code

    MergeToWORD(codLabelID);
    //IF CONFIRM(strFileNameIn,TRUE) THEN ;
    END;

    }
    CODE
    {

    PROCEDURE CreateXMLDataDoc@1100502000(LabelID@1100502003 : ARRAY [4] OF Code[20];VAR xmlData@1100502000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60");
    VAR
    TopNode@1100502002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
    Node@1100502001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
    NodeAttribute@1100502004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF85-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMAttribute";
    BEGIN
    //CREATE(xmlData,TRUE,TRUE);
    // ^- Create on Client
    CREATE(xmlData,TRUE,FALSE);
    xmlData.async(FALSE);

    Node := xmlData.createProcessingInstruction('xml','version=''1.0'' ' +
    'encoding=''UTF-8'' ' +
    'standalone=''no''');
    xmlData.appendChild(Node);

    Node := xmlData.createElement('Object');

    NodeAttribute := xmlData.createAttribute('type');
    NodeAttribute.value := 'FlorEcomLabelMessage';
    Node.attributes.setNamedItem(NodeAttribute);

    NodeAttribute := xmlData.createAttribute('id');
    NodeAttribute.value := 11078850; // value of formID
    Node.attributes.setNamedItem(NodeAttribute);

    NodeAttribute := xmlData.createAttribute('url');

    // FieldXX must be the Primary Key
    NodeAttribute.value := 'view=SORTING(Field25)%26position=Field25=0(' + LabelID[1] + ')%26servertype=MSSQL';

    Node.attributes.setNamedItem(NodeAttribute);

    xmlData.appendChild(Node);
    END;

    PROCEDURE FindStyleSheetGUID@1100502001(codStickerID@1100502000 : Code[20];VAR GUIDStyleSheet@1100502007 : GUID) : Boolean;
    VAR
    rsSticker@1100502001 : Record 11078829;
    rsStyleSheetHeader@1100502002 : Record 680;
    rsStyleSheet@1100502003 : Record 2000000066;
    codStyleSheetHeader@1100502004 : Code[20];
    txtStyleSheetName@1100502005 : Text[50];
    ReturnValue@1100502006 : Boolean;
    BEGIN
    ReturnValue := FALSE;

    rsSticker.SETFILTER(Code,'=%1',codStickerID);
    IF rsSticker.FINDFIRST THEN
    BEGIN
    codStyleSheetHeader := rsSticker."Style Sheet Header";
    rsStyleSheetHeader.SETFILTER(Code,'=%1',codStyleSheetHeader);
    IF rsStyleSheetHeader.FINDFIRST THEN
    BEGIN
    txtStyleSheetName := rsStyleSheetHeader.Description;
    rsStyleSheet.SETFILTER(Name,'=%1',txtStyleSheetName);
    rsStyleSheet.SETFILTER("Object Type",'=%1',rsStyleSheet."Object Type"::UnAttached);
    IF rsStyleSheet.FINDFIRST THEN BEGIN
    GUIDStyleSheet := rsStyleSheet."Style Sheet ID";
    ReturnValue := TRUE;
    END;
    END;
    END;

    EXIT(ReturnValue);
    END;


    PROCEDURE GetLabelInfo@1100502004(VAR codLabelID@1100502000 : ARRAY [4] OF Code[20]) : Text[255];
    VAR
    ReturnValue@1100502002 : Text[255];
    rsFlorecomLabelMessage@1100502001 : Record 11078830;
    BEGIN
    //rsFlorecomLabelMessage.SETFILTER(rsFlorecomLabelMessage."Lot No.",codLabelID[1]);
    //rsFlorecomLabelMessage.SETFILTER(rsFlorecomLabelMessage."Florecom Reference No.",codLabelID[1]);
    rsFlorecomLabelMessage.SETFILTER(rsFlorecomLabelMessage."Label No.",codLabelID[1]);

    IF rsFlorecomLabelMessage.FINDFIRST THEN
    BEGIN
    ReturnValue := rsFlorecomLabelMessage.Sticker;

    codLabelID[2] := rsFlorecomLabelMessage."Vendor No.";
    codLabelID[3] := rsFlorecomLabelMessage."Sales Order No.";
    codLabelID[4] := rsFlorecomLabelMessage.Sticker;
    END;

    {
    ELSE BEGIN
    CLEAR(rsFlorecomLabelMessage);
    rsFlorecomLabelMessage.SETFILTER(rsFlorecomLabelMessage."Lot No.",codLabelID[1]);

    IF rsFlorecomLabelMessage.FINDFIRST THEN
    BEGIN
    ReturnValue := rsFlorecomLabelMessage.Sticker;

    codLabelID[1] := rsFlorecomLabelMessage."Florecom Reference No.";
    codLabelID[2] := rsFlorecomLabelMessage."Vendor No.";
    codLabelID[3] := rsFlorecomLabelMessage."Sales Order No.";
    codLabelID[4] := rsFlorecomLabelMessage.Sticker;
    END;
    END;
    }
    EXIT(ReturnValue);
    END;

    PROCEDURE MergeToWORD@1100502003(VAR codLabelID@1100502006 : ARRAY [4] OF Code[20]) : Text[255];
    VAR
    xmlData@1100502009 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
    xmlApp@1100502008 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
    guidStyleSheet@1100502007 : GUID;
    strFileNameData@1100502005 : Text[255];
    strFileNameResult@1100502003 : Text[255];
    cuAppManagement@1100502002 : Codeunit 1;
    objWord@1100502001 : Automation "{00020905-0000-0000-C000-000000000046} 8.5:{000209FF-0000-0000-C000-000000000046}:'Microsoft Word 14.0 Object Library'.Application" WITHEVENTS;
    vbFalse@1100502000 : Boolean;
    intFileNameUniKey@1100502010 : Integer;
    BEGIN
    //CREATE(xmlData);
    CreateXMLDataDoc(codLabelID,xmlData);

    CREATE(xmlApp);

    strFileNameData := 'C:\temp\DataXML.xml';//'\\v-dc-01\data\Adf_Soft\WSResult\Nav\DataXML.xml';
    RANDOMIZE();
    intFileNameUniKey := RANDOM(1000);
    strFileNameResult := 'C:\temp\' + FORMAT(intFileNameUniKey) + '.xml' ;//App.xml';

    xmlData.save(strFileNameData);
    // get Labelcode from LabelTable

    GetLabelInfo(codLabelID);//'TEST';

    IF FindStyleSheetGUID(codLabelID[4],guidStyleSheet) THEN
    BEGIN
    cuAppManagement.LaunchApp(xmlData,guidStyleSheet,xmlApp);
    xmlApp.save(strFileNameResult);

    CREATE(objWord,FALSE,FALSE); // start Word
    objWord.Visible(TRUE); // Winword visible
    objWord.Activate; // Winword active
    objWord.Documents.Open(strFileNameResult);

    vbFalse := FALSE;
    objWord.ActiveDocument.Close(vbFalse);

    objWord.Quit(vbFalse);
    IF EXISTS(strFileNameResult) THEN
    ERASE(strFileNameResult);
    CLEAR(objWord);
    END;

    CLEAR(xmlData);
    CLEAR(xmlApp);

    EXIT(strFileNamePDF);
    END;

    BEGIN
    END.
    }
    }
Sign In or Register to comment.