Parameters coutputname
Local loSessionx, loXFFx, cout, m.koniec, m.lavastrana, m.top, m.od, m.do, m.sirka, m.o1, m.o2
cout=LEFT(m.coutputname,LEN(m.coutputname)-5)
loSessionx= xfrx("XFRX#INIT")
lnRetValx =  loSessionx.SetParams(cout,,,,,,"XFF")
If lnRetValx = 0
	loSessionx.ProcessReport(m.repo_name)
	loSessionx.finalize()
	IF FILE(cout+".xff")
		SELECT 0
		USE (cout+".xff") ALIAS xffx
		DELETE FOR rctype="-"
		LOCATE FOR rctype="P"
		IF FOUND()
			m.sirka=xffx.Width
		ELSE 
			USE IN xffx
			RETURN 
		ENDIF 
		SELECT * , RECNO() AS koniec, RECNO() as riadok FROM xffx INTO CURSOR axffx WHERE rctype="S" READWRITE 
		m.koniec=RECCOUNT("xffx")
		SELECT MIN(xffx.left) as left from xffx INTO CURSOR minleft WHERE rctype="T"
		m.lavastrana=minleft.left
		USE IN minleft
		SELECT axffx
		GO BOTTOM 
		DO WHILE .T.
			REPLACE koniec WITH m.koniec
			m.koniec=axffx.riadok
			IF RECNO()>1
				SKIP -1
			ELSE 
				EXIT 
			ENDIF 
		ENDDO 
		GO TOP 
		SCAN FOR data1<>"Detail"
			m.od=axffx.riadok
			m.do=axffx.koniec
			SELECT DISTINCT xffx.top FROM xffx WHERE rctype="T" And BETWEEN(RECNO(), m.od, m.do) INTO CURSOR topy
			IF RECCOUNT()>0
				SCAN ALL 
					m.top=topy.Top
					SELECT * FROM xffx WHERE rctype="T" And xffx.Top=m.top AND BETWEEN(RECNO(), m.od, m.do) ORDER BY xffx.Left INTO CURSOR riadok
					IF RECCOUNT()>0
						GO TOP 
						m.obj=riadok.Name
						SELECT * FROM riadok INTO CURSOR riadok1 READWRITE WHERE riadok.name=m.obj
						REPLACE riadok1.text WITH ""
						m.font=riadok.Font
						m.fontsize=riadok.FontSize
						m.fontbold=IIF(riadok.bold,"B","")
						m.o2=0
						SELECT riadok
						SCAN ALL 
							m.o1=""
							IF riadok.Left>m.o2
								DO WHILE .T.
									m.o1=m.o1+" "
									IF TXTWIDTH(m.o1,m.font,m.fontsize,m.fontbold)*FONTMETRIC(6,m.font,m.fontsize,m.fontbold)/80>(riadok.Left-m.o2)/10000
										EXIT 
									ENDIF 
								ENDDO 
								SELECT riadok1
								REPLACE riadok1.text WITH riadok1.text+m.o1
								SELECT riadok
							ENDIF 
							m.o1=ALLTRIM(riadok.Text)
							m.o2=riadok.Left+riadok.Width
							DO WHILE .T.
								IF TXTWIDTH(m.o1,m.font,m.fontsize,m.fontbold)*FONTMETRIC(6,m.font,m.fontsize,m.fontbold)/90>riadok.Width/10000
									EXIT 
								ELSE 
									DO CASE 
										CASE riadok.Align="L"
											m.o1=m.o1+" "
										CASE riadok.Align="R"
											m.o1=" "+m.o1
										OTHERWISE 
											m.o1=PADC(m.o1,LEN(m.o1)+1," ")
									ENDCASE 
								ENDIF 
							ENDDO 
							SELECT riadok1
							REPLACE riadok1.text WITH riadok1.text+m.o1
							SELECT riadok
							m.o1=""
						ENDSCAN 
						SELECT xffx
						LOCATE FOR xffx.Name=m.obj
						IF FOUND()
							REPLACE xffx.text WITH riadok1.text, xffx.left WITH m.lavastrana, xffx.width WITH m.sirka
							DELETE FOR xffx.top=m.top And xffx.name<>m.obj AND BETWEEN(RECNO(), m.od, m.do)
						ENDIF 
						SELECT topy
					ENDIF 
				ENDSCAN 
			ENDIF 
			SELECT axffx
		ENDSCAN 
	ENDIF
	DO pozavirej WITH "xffx, axffx, koniec, topy, riadok, riadok1"
	loXFF = xfrx("XFRX#DRAW")
	IF loXFF.openDocument(cout+".xff")
*		lnRetVal = loSessionx.SetParams(coutputname,,.t.,,,,"XLSPLAIN")
*		lnRetVal = loSessionx.SetParams(coutputname,,.t.,,,,"NATIVE_PFXLSX")
		lnRetVal = loSessionx.SetParams(coutputname,,.t.,,,,"NATIVE_FXLSX")
		IF lnRetVal = 0
			loSessionx.TransformReport(loXFF)
		ENDIF 
	ENDIF 
	RELEASE loxff
	IF FILE(cout+".xff")
		ERASE (cout+".xff")
	ENDIF 
	IF FILE(cout+".fpt")
		ERASE (cout+".fpt")
	ENDIF 
	IF FILE(cout+".cdx")
		ERASE (cout+".cdx")
	ENDIF 
ENDIF 
