Skip to main content
4everJang
Legend
March 30, 2019
Answered

Applying another Table format via script

  • March 30, 2019
  • 1 reply
  • 1772 views

Looking for a way to change the table format (drop down list in the Table Designer) via scripting. Does anyone know what the Fcode for some 'Apply Table Format' command is? I have no idea what the command would be called like, so GetNamedCommand will not help me here. Should I use SetProps on the TblFormat instead? Has anyone done this before?

This topic has been closed for replies.
Correct answer Klaus Göbel

Hi Jang,

here's a code snippet from Bharat Prakash

function changeTblTag(active)

{

       

    if(active.BookIsSelected || active.FirstSelectedComponentInBook)

        iterateBook(active);

    else if(active.ObjectValid())

        {

                        var flow = active.FirstFlowInDoc;

                        while(flow.ObjectValid())       

                        {

                            var i = 0;

                            var textItems = flow.GetText(Constants.FTI_TblAnchor) // Get all tables in the flow

                           

                            var newtblfmt = active.GetNamedTblFmt(finalTag)

                            while(i<textItems.length)

                            {

                                if(isTableInReferenceOrHiddenPageOrMasterPage(textItems.obj.TextLoc))

                                    i++

                                else

                                {

                                    var currtblfmttag = textItems.obj.TblTag

                                    if(currtblfmttag == iniTag)

                                    {

                                        textItems.obj.SetProps (newtblfmt.GetProps())

                                        tblCount++

                                     }  

                                    i++

                                }

                               

                                if(i == textItems.length)

                                    break;

                            }

                        flow = flow.NextFlowInDoc

                        }

                      //       savedoc(active);  

          }

   

    if(DeleteFormat)

            iniTag.Delete()

}

1 reply

Klaus Göbel
Klaus GöbelCorrect answer
Legend
March 30, 2019

Hi Jang,

here's a code snippet from Bharat Prakash

function changeTblTag(active)

{

       

    if(active.BookIsSelected || active.FirstSelectedComponentInBook)

        iterateBook(active);

    else if(active.ObjectValid())

        {

                        var flow = active.FirstFlowInDoc;

                        while(flow.ObjectValid())       

                        {

                            var i = 0;

                            var textItems = flow.GetText(Constants.FTI_TblAnchor) // Get all tables in the flow

                           

                            var newtblfmt = active.GetNamedTblFmt(finalTag)

                            while(i<textItems.length)

                            {

                                if(isTableInReferenceOrHiddenPageOrMasterPage(textItems.obj.TextLoc))

                                    i++

                                else

                                {

                                    var currtblfmttag = textItems.obj.TblTag

                                    if(currtblfmttag == iniTag)

                                    {

                                        textItems.obj.SetProps (newtblfmt.GetProps())

                                        tblCount++

                                     }  

                                    i++

                                }

                               

                                if(i == textItems.length)

                                    break;

                            }

                        flow = flow.NextFlowInDoc

                        }

                      //       savedoc(active);  

          }

   

    if(DeleteFormat)

            iniTag.Delete()

}

4everJang
4everJangAuthor
Legend
March 30, 2019

Hello Klaus,

Thanks for digging this up. It is a lot of code I don't need, but the one vital line solved my problem. Getting the properties of the named table format and applying all those properties to the table object makes sense. And it works.

Ciao