How to set print area, fit to width in page setup and paper size index for NATIVE_FXLSX and NATIVE_PFXLSX

(for XFRX early 15.6) 

XFRX#INIT and direct output

m.loSession=EVALUATE([xfrx("XFRX#INIT")]) 
m.lnRetVal = m.loSession.SetParams("test.xlsx",,,,,,"NATIVE_FXLSX")
IF m.lnRetVal=0
   m.loHACK=CREATEOBJECT("_XFRXHACK",m.loSession)
   m.loSession.ProcessReport("_reports\basetext")
   m.loSession.Finalize()
   RELE m.loHACK
END IF

  
XFRX#INIT , direct output to XFF and transform to

m.loXFF=EVALUATE([xfrx("XFRX#DRAW")]) 
m.loXFF.OpenDocument("out.xff")
m.loSession=EVALUATE([xfrx("XFRX#INIT")]) 
m.lnRetVal = m.loSession.SetParams("test.xlsx",,,,,,"NATIVE_FXLSX")
IF m.lnRetVal=0
   m.loHACK=CREATEOBJECT("_XFRXHACK",m.loSession)
   m.loSession.TransformReport(m.loXFF)
   RELE m.loHACK
END IF 


XFRX#LISTENER

m.loSession=EVALUATE([xfrx("XFRX#LISTENER")])  
m.lnRetVal = m.loSession.SetParams("test.xlsx",,,,,,"NATIVE_FXLSX") 
IF m.lnRetVal=0
   m.loHACK=CREATEOBJECT("_XFRXHACK",m.loSession)
   REPORT FORM ("_reports\firstreport") OBJECT m.loSession
   RELE m.loHACK 
END IF 


HACK class

DEFINE CLASS _XFRXHACK AS CUSTOM
   oEWriter=.NULL.
   cTarget=""
   nVersion=0
   DIMENSION aps(256,3)
   PROCEDURE Init(m.loSession)
      m.loSession=IIF(TYPE("m.loSession.oxfSession")="O",m.loSession.oxfSession,m.loSession)
      This.nVersion=VAL(CHRTRAN(m.loSession.GetVersion();
                       ,CHRTRAN(m.loSession.GetVersion(),"0123456789",""),""))
      This.cTarget=m.loSession.cTarget
      DO CASE
         CASE This.cTarget=="NATIVE_FXLSX" OR This.cTarget=="NATIVE_PFXLSX"
              =BINDEVENT(m.loSession.oDocumentWriter,"RenderPage",This,"RenderPageBefore",0)
              =BINDEVENT(m.loSession.oDocumentWriter,"RenderPage",This,"RenderPageAfter",1)
      ENDCASE
      This.oEWriter=m.loSession.oDocumentWriter
      This.InitPaperSize()      
   ENDPROC

   PROCEDURE RenderPageAfter(m.tnHeight, m.tnWidth, m.tnPageNo)
      LOCAL m.liSele
      m.liSele=SELECT()
      WITH This.oEWriter.oOXML
      SELECT (.Alias) 
      SET KEY TO "header"
      SET FILTER TO XX003=.nPageNo
      GO TOP
      IF NOT EOF()
         REPLACE XX001 WITH STRTRAN(XX001,[<dimension ref="A1:A1"/>],;
             '<sheetPr><pageSetUpPr fitToPage="1"/></sheetPr>'+CHR(13)+CHR(10)+;
             [<dimension ref="A1:]+.CIToC(.nColNo)+LTRIM(STR(.nRowNo,11))+["/>])
      ENDIF
      SET KEY TO
      SET FILTER TO

      m.lcPom=[  <definedName name="_xlnm.Print_Area" localSheetId="]+LTRIM(STR(.nPageNo-1,11))+;
              [">']+StrTranHTMLStringOO(STRTRAN(.cPageDisplayName,"'","''"))+;
              ['!$A$1:$]+.CIToC(.nColNo)+[$]+LTRIM(STR(.nRowNo,11))+[ </definedName>]
      INSERT INTO (.Alias) (XX000,XX001) VALUES("workbook:dn",m.lcPom)
      ENDWITH

      SELECT (m.liSele)
   ENDPROC

   PROCEDURE RenderPageBefore(m.tnHeight, m.tnWidth, m.tnPageNo)
      LOCAL m.liSele, m.lnYY, loEWriter
      m.liSele=SELECT()
      m.loEWriter=This.oEWriter
      WITH m.loEWriter.oOXML
      SELECT (loEWriter.rpivotsalias)
      GO BOTTOM
      m.lnYY=YY
      SELECT (.Alias) 
      SET FILTER TO XX003=.nPageNo
      SET KEY TO "footer"
      GO TOP
      IF NOT EOF()
         REPLACE XX001 WITH STRTRAN(XX001,[paperSize="9"],;
                [fitToHeight="]+LTRIM(STR(MAX(INT(m.lnYY/(m.loEWriter.nPageHeight-m.loEWriter.nTopMargin-m.loEWriter.nBottomMargin)),1),11))+;
                [" paperSize="]+LTRIM(STR(This.GetPaperSize(m.loEWriter.nPageWidth, m.loEWriter.nPageHeight),11))+["])
      ENDIF
      SET KEY TO
      SET FILTER TO
      ENDWITH
      SELECT (m.liSele)
   ENDPROC

   PROCEDURE GetPaperSize(m.tnWidth, m.tnHeight)      
      LOCAL m.lnPaperSize
      FOR m.lnPaperSize=1 TO ALEN(This.aps,1)
          IF This.aps(m.lnPaperSize,2)=m.tnWidth AND This.aps(m.lnPaperSize,3)=m.tnHeight
             EXIT
          ENDIF
      NEXT
      RETURN m.lnPaperSize
   ENDPROC
  
   PROCEDURE InitPaperSize()
      STORE 0 TO This.aps
      This.aps(1,2) =  85000
      This.aps(1,3) = 110000
      This.aps(2,2) =  85000
      This.aps(2,3) = 110000
      This.aps(3,2) = 110000
      This.aps(3,3) = 170000
      This.aps(4,2) = 170000
      This.aps(4,3) = 110000
      This.aps(5,2) =  85000
      This.aps(5,3) = 140000      
      This.aps(6,2) =  55000
      This.aps(6,3) =  85000
      This.aps(7,2) =  72500
      This.aps(7,3) =  10500
      This.aps(8,2) = 116929
      This.aps(8,3) = 165354
      This.aps(9,2) =  82677
      This.aps(9,3) = 116929
      This.aps(10,2) =  82677
      This.aps(10,3) = 116929
      This.aps(11,2) =  58268
      This.aps(11,3) =  82677
      This.aps(12,2) =  98425
      This.aps(12,3) = 139370
      This.aps(13,2) =  71654
      This.aps(13,3) = 101181
      This.aps(14,2) =  85000
      This.aps(14,3) = 130000
      This.aps(15,2) =  84646
      This.aps(15,3) = 108268
      This.aps(16,2) = 100000
      This.aps(16,3) = 140000
      This.aps(17,2) = 110000
      This.aps(17,3) = 170000
      This.aps(18,2) =  85000
      This.aps(18,3) = 110000
      This.aps(19,2) =  38750
      This.aps(19,3) =  88750
      This.aps(20,2) =  41250
      This.aps(20,3) =  85000
      This.aps(21,2) =  45000
      This.aps(21,3) = 103750
      This.aps(22,2) =  45000
      This.aps(22,3) = 110000
      This.aps(23,2) =  50000
      This.aps(23,3) = 115000
      This.aps(24,2) =  45000
      This.aps(24,3) = 103750
      This.aps(25,2) =  47500
      This.aps(25,3) = 110000
      This.aps(26,2) =  50000
      This.aps(26,3) = 115000
      This.aps(27,2) =  43307
      This.aps(27,3) =  86614
      This.aps(28,2) =  63779
      This.aps(28,3) =  90157
      This.aps(29,2) = 127559
      This.aps(29,3) = 180315
      This.aps(30,2) =  90157
      This.aps(30,3) = 127559
      This.aps(31,2) =  44881
      This.aps(31,3) = 63779
      This.aps(32,2) =  44881
      This.aps(32,3) =  90157
      This.aps(33,2) =  98425
      This.aps(33,3) = 138976
      This.aps(34,2) =  69291
      This.aps(34,3) =  98425
      This.aps(35,2) =  69291
      This.aps(35,3) =  49212
      This.aps(36,2) =  43307
      This.aps(36,3) =  90551
      This.aps(37,2) =  38750
      This.aps(37,3) =  75000
      This.aps(38,2) =  36250
      This.aps(38,3) =  65000
      This.aps(39,2) = 148750
      This.aps(39,3) = 110000
      This.aps(40,2) =  85000
      This.aps(40,3) = 120000
      This.aps(41,2) =  85000
      This.aps(41,3) = 130000
          
      This.aps(256, 2) = 104330 && 265 &&270 mm
      This.aps(256, 3) = 149606 && 380 &&385 mm
   ENDPROC
ENDDEFINEÂ