Skip to main content

OfficeXML writers

DotHRB provides simple, fast writers for exporting result sets into various OfficeXML formats like .xlsx, .ods, and .docx. While not intended as full-featured modules, they offer an efficient way to quickly generate common document types.

Important

These are lightweight, high-speed exporting functions, not full-scale document manipulation engines. They are optimized strictly for streaming clean tabular data directly into OfficeXML formats without complex external dependencies.

#include "dothrb.ch"

class DemoController from ApiController

method init constructor

method get
method getfile

end class

method init(cName) class DemoController

::super:init(cName)

::authorize()

return Self

method getfile() class DemoController

local hParams := ::getRequestParams(ALLOW_METHOD_GET)
local db
local res
local cFile
local cName := "demo.xlsx" // or demo.ods, demo.pdf, demo.docx, demo.csv

db := getDbConn(::hClaims)
res := db:useModelRead(new DemoModel(), hParams)
db:close()

cFile := res2file(res, cName) // create cName file with res values as rows/cols

return ::sendAttachment(cFile, cName)

or for xlsx and ods

#include "dothrb.ch"

function main()

local oWks := new WksFile("Test.xlsx") // or "Test.ods"

oWks:cell(1,1, "Test")
oWks:cell(1,2, 10)
oWks:cell(1,3, date())

oWks:end()

return nil

for docx

#include "dothrb.ch"

function main()

local oWps := new WpsFile("Test.docx")

oWps:LogicCode("landscape", false)
oWps:NumCode("paperw", 8.27)
oWps:NumCode("paperh", 11.69)
oWps:NumCode("margl", .35)
oWps:NumCode("margr", .35)
oWps:NumCode("margt", .5)
oWps:NumCode("margb", .5)
oWps:setFontSize(14)

oWps:paragraph("Test")
oWps:newline()
oWps:paragraph("10")
oWps:newline()
oWps:paragraph(dtoc(date()))
oWps:newline()
oWps:end()

return nil