The copytopptx procedure export an opened cursor / table to pptx format.
No automation is used and no need for Ms Office or other Office package to be installed.
[code Foxpro]* demo *
CLOSE DATABASES ALL
CLEAR ALL
USE (HOME(2)+'data\customer')
DO copytopptx WITH 'customer','3',.T.,"company,contact,MAXORDAMT"
USE IN customer
**********************************************************************************
**********************************************************************************
* PROCEDURE copytopptx *
* Version 1.2 *
* export a cursor / table to pptx format *
* no need for MsOffice to be installed *
* *
* Parameters *
* cCur name of the table / cursor *
* lcFileName optional, name of the docx *
* llHead optional, .T. first row of exported table contain column names *
* lcFFields optional, list (subset) of fields to be outputed *
**********************************************************************************
**********************************************************************************
PROCEDURE copytopptx
* Version 1.2
# DEFINE theLanguage "ro-RO"
# DEFINE theNoOfRows 12 && nbumber of rows / slide
# DEFINE theSildeTitle "Page" && tile of the slides
LPARAMETERS cCur,lcFileName,llHead,lcFFields
DECLARE INTEGER ShellExecute IN SHELL32.DLL INTEGER nWinHandle,STRING cOperation,STRING cFileName,STRING cParameters,STRING cDirectory,INTEGER nShowWindow
DECLARE Sleep IN kernel32 INTEGER
LOCAL lcMyPath,lcDir,loerr as Exception
LOCAL lnRowsNo,lnColsNo,laFields[1,5],lnCurRow,lnCurCol,lnTime,ltTime,lcSetDec,lnColsNoAll,laFieldsAll[1],lnII,lSetTalk,lnFFields,laFFields[1]
LOCAL lcValue,lcType,lnDec,cMax,ldValue
LOCAL lcCurr,llLeftCurr,llBelow7
LOCAL lnFHSh,lcLenStr,lcLenIdx,lnCountbefore,lcField,lcCurRow,ofile,lcSource,lcZipFileName,oShell,oFolder,lcColWidth,lnSlideNo,lntheNoOfRows,lnCurSlide
IF PCOUNT() < 1
MESSAGEBOX("Nothing to export",48,"No pptx generated")
RETURN
ELSE
IF VARTYPE(m.cCur) $ "CV"
IF !USED(m.cCur)
USE (m.cCur)
ENDIF
ELSE
MESSAGEBOX("Not a cursor/table name",48,"No pptx generated")
RETURN
ENDIF
ENDIF
IF PCOUNT() < 2
lcFileName = FORCEEXT(SYS(2015),"pptx")
ELSE
IF VARTYPE(m.lcFileName) $ "CV"
lcFileName = FORCEEXT(m.lcFileName,"pptx")
ELSE
lcFileName = FORCEEXT(SYS(2015),"pptx")
ENDIF
ENDIF
IF PCOUNT() < 3
llHead = .F.
ELSE
IF VARTYPE(m.llHead) <> "L"
llHead = .F.
ENDIF
ENDIF
IF FILE(FORCEEXT(m.lcFileName,"pptx"))
IF MESSAGEBOX(FORCEEXT(m.lcFileName,"pptx")+" already exist."+CHR(13)+"Overwrite?",4+48) = 7
RETURN
ELSE
ERASE (FORCEEXT(m.lcFileName,"pptx")) RECYCLE
ENDIF
ENDIF
IF PCOUNT()<4
lcFFields = ""
ELSE
IF VARTYPE(m.lcFFields) <> "C"
lcFFields = ""
ELSE
lnFFields = ALINES(laFFields,m.lcFFields,1+4,",")
ENDIF
ENDIF
lSetTalk = SET("Talk")
SET TALK OFF
lnColsNoAll=AFIELDS(m.laFieldsAll,m.cCur)
lnColsNo = 0
FOR lnCurCol = 1 TO m.lnColsNoAll
IF m.laFieldsAll[m.lnCurCol,2] $ "NFYBIDTLCVM"
IF !EMPTY(m.lcFFields)
IF ASCAN(m.laFFields,laFieldsAll[m.lnCurCol,1],1,-1,-1,1+2+4)=0
LOOP
ENDIF
ENDIF
lnColsNo = m.lnColsNo + 1
DIMENSION laFields[m.lnColsNo,5]
laFields[m.lnColsNo,1] = laFieldsAll[m.lnCurCol,1]
laFields[m.lnColsNo,2] = laFieldsAll[m.lnCurCol,2]
laFields[m.lnColsNo,3] = laFieldsAll[m.lnCurCol,3]
laFields[m.lnColsNo,4] = laFieldsAll[m.lnCurCol,4]
laFields[m.lnColsNo,5] = IIF(m.lnColsNo<=26,[],CHR(64+FLOOR((m.lnColsNo-1)/26)))+CHR(65+MOD(m.lnColsNo-1,26))
ELSE
LOOP
ENDIF
NEXT
lcColWidth = LTRIM(STR(FLOOR(8229600 / m.lnColsNo)))
SELECT (m.cCur)
COUNT TO m.lnRowsNo
lnRowsNo = m.lnRowsNo + IIF(m.llHead,1,0)
lntheNoOfRows = theNoOfRows + IIF(m.llHead,0,1) && number of rows / slide
lnSlideNo = CEILING(m.lnRowsNo / m.lntheNoOfRows)
lcMyPath=''
IF !EMPTY(JUSTPATH(m.lcFileName))
lcMyPath=ADDBS(JUSTPATH(m.lcFileName))
SET DEFAULT TO (m.lcMyPath)
ELSE
lcMyPath = ADDBS(JUSTPATH(FULLPATH(m.lcFileName)))
ENDIF
lcSetDec = SET("Decimals")
SET DECIMALS TO 13
SELECT (m.cCur)
SCAN NEXT m.lntheNoOfRows
FWRITE(m.lnFHSh,[<a:tr h="370840">])
FOR lnCurCol = 1 TO m.lnColsNo
lcValue = EVALUATE(m.laFields[m.lnCurCol,1])
lcType = m.laFields[m.lnCurCol,2]
lnDec = m.laFields[m.lnCurCol,4]
IF ISNULL(m.lcValue)
lcValue = ''
lcType = 'C'
ENDIF
DO CASE
CASE m.lcType $ "CV" && character
lcValue = htmspec(RTRIM(m.lcValue))
CASE m.lcType == "I" && integer
lcValue = LTRIM(STR(m.lcValue))
CASE m.lcType $ "NF" && number, float
lcValue = LTRIM(STR(m.lcValue,m.laFields[m.lnCurCol,3],m.lnDec))
CASE m.lcType == "D" && date
lcValue = DTOC(m.lcValue)
CASE m.lcType == "T" && time
lcValue = TTOC(m.lcValue)
CASE m.lcType == "L" && boolean
lcValue = IIF(m.lcValue ,'True','False')
CASE m.lcType == "Y" && currency
IF m.llLeftCurr
lcValue = m.lcCurr + LTRIM(STR(m.lcValue,21,4))
ELSE
lcValue = LTRIM(STR(m.lcValue,21,4)) + ' ' + m.lcCurr
ENDIF
CASE m.lcType == "B" && double
lcValue = LTRIM(STR(m.lcValue,21,m.lnDec))
CASE m.lcType == "M" && memo
lcValue = htmspec(RTRIM(m.lcValue))
ENDCASE
FWRITE(m.lnFHSh,[<a:tc>])
FWRITE(m.lnFHSh,[<a:txBody>])
FWRITE(m.lnFHSh,[<a:bodyPr/>])
FWRITE(m.lnFHSh,[<a:lstStyle/>])
FWRITE(m.lnFHSh,[<a>])
FWRITE(m.lnFHSh,[<a:r>])
FWRITE(m.lnFHSh,[<a:rPr lang="] + theLanguage + [" dirty="0" smtClean="0"/>])
FWRITE(m.lnFHSh,[<a:t>] + m.lcValue + [</a:t>])
FWRITE(m.lnFHSh,[</a:r>])
FWRITE(m.lnFHSh,[<a:endParaRPr lang="] + theLanguage + [" dirty="0"/>])
FWRITE(m.lnFHSh,[</a>])
FWRITE(m.lnFHSh,[</a:txBody>])
FWRITE(m.lnFHSh,[<a:tcPr/>])
FWRITE(m.lnFHSh,[</a:tc>])
NEXT
FWRITE(m.lnFHSh,[</a:tr>])
ENDSCAN
IF !EOF()
SKIP
ENDIF
* End document
FWRITE(m.lnFHSh,[</a:tbl>])
FWRITE(m.lnFHSh,[</a:graphicData>])
FWRITE(m.lnFHSh,[</a:graphic>])
FWRITE(m.lnFHSh,[</p:graphicFrame>])
FWRITE(m.lnFHSh,[</p:spTree>])
FWRITE(m.lnFHSh,[</p:cSld>])
FWRITE(m.lnFHSh,[<p:clrMapOvr>])
FWRITE(m.lnFHSh,[<a:masterClrMapping/>])
FWRITE(m.lnFHSh,[</p:clrMapOvr>])
FWRITE(m.lnFHSh,[</p:sld>])
FCLOSE(m.lnFHSh)
NEXT
*****
SET DECIMALS TO &lcSetDec
lcSource = m.lcMyPath + m.lcDir &&"<< fully qualified path name to some folder >>"
lcZipFileName = m.lcMyPath + FORCEEXT(m.lcFileName,'zip') &&"<< fully qualified path name to some zip file >>"
TRY
IF FILE(m.lcZipFileName)
ERASE (m.lcZipFileName)
ENDIF
CATCH TO m.loerr
ENDTRY
TRY
IF FILE(m.lcFileName)
ERASE (m.lcFileName)
ENDIF
CATCH TO m.loerr
ENDTRY
llBelow7 = OS(3)<'6' OR OS(3)='6' AND OS(4)<'1'
IF m.llBelow7 && Win XP
TRY
FOR EACH ofile IN m.oFolder
lnCountbefore = m.oShell.NameSpace( m.lcSource ).items.count
oShell.NameSpace( m.lcZipFileName ).movehere( m.ofile )
sleep(100)
ENDFOR
CATCH TO loErr
ENDTRY
llErr = .T.
DO WHILE llErr
TRY
llErr = .F.
RENAME (m.lcZipFileName) TO (FORCEEXT(m.lcZipFileName,"pptx"))
CATCH
llErr = .T.
sleep(100)
ENDTRY
ENDDO
DO cleanup WITH m.lcDir
ELSE && WIN 7
TRY
FOR EACH ofile IN m.oFolder
lnCountbefore = m.oShell.NameSpace( m.lcSource ).items.count
oShell.NameSpace( m.lcZipFileName ).movehere( m.ofile )
sleep(100)
DO WHILE m.lnCountbefore = m.oShell.NameSpace( m.lcSource ).items.count
sleep(100)
ENDDO
ENDFOR
CATCH TO loErr
ENDTRY
TRY
RD (m.lcDir)
CATCH TO m.loErr
ENDTRY
RENAME (m.lcZipFileName) TO (FORCEEXT(m.lcZipFileName,"pptx"))
ENDIF
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.