diff --git a/odsfile.lua b/odsfile.lua index c374037..a32e370 100644 --- a/odsfile.lua +++ b/odsfile.lua @@ -338,6 +338,12 @@ function updateZip(zipfile, updatefile) print ("Updating an ods file.\n" ..command .."\n Return code: ", os.execute(command)) end +function save(filename, content) + local f = io.open(filename, "w") + f:write(content) + f:close() +end + M.load= load M.loadContent = loadContent M.getTable= getTable @@ -362,5 +368,6 @@ M.findLastRow = findLastRow M.insert = insert -- for updateing the archive. Depends on external zip utility M.updateZip= updateZip +M.save = save return M diff --git a/odsfile.sty b/odsfile.sty index 9a8216a..781a406 100644 --- a/odsfile.sty +++ b/odsfile.sty @@ -35,6 +35,11 @@ rowseparator=[[\\n]] \define@key{includespread}{columnbreak}{% \luaexec{columnbreak="\luatexluaescapestring{\unexpanded{#1}}{}"}% } + +\define@key{includespread}{save}{% + \luaexec{odssave="\luatexluaescapestring{#1}"}% +} + \define@key{includespread}{coltypes}{% \luaexec{coltypes="\luatexluaescapestring{\unexpanded{#1}}"}% } @@ -74,6 +79,7 @@ range = {nil,nil,nil,nil} columns = nil templates = {} row = {} +odssave = nil body = nil odsfilename = "" currenttemplate = nil @@ -119,6 +125,7 @@ odslastnl = "\\OdsLastNl" rowseparator = "" columns=nil currenttemplate = nil + odssave = nil rowtemplate = nil celltpl = "-{value}" columnbreak = "\\linebreak{}" @@ -218,7 +225,11 @@ odslastnl = "\\OdsLastNl" content = table.concat(content, odsnl .. " " ..rowseparator) .. odslastnl local result = odsreader.interp(templates[currenttemplate],{content=content,coltypes=coltypes,colheading=colheading,rowsep=rowseparator}) print(result) - tex.sprint(result) + if odssave then + odsreader.save(odssave, result) + else + tex.sprint(result) + end else local content = {} currenttemplate = currenttemplate or "empty" @@ -228,7 +239,11 @@ odslastnl = "\\OdsLastNl" content = table.concat(content,rowseparator) local result = odsreader.interp(templates[currenttemplate],{content=content,coltypes=coltypes,colheading=colheading,rowsep=rowseparator}) print(result) - tex.sprint(result) + if odssave then + odsreader.save(odssave, result) + else + tex.sprint(result) + end end }% }% diff --git a/odsfile.tex b/odsfile.tex index 1f05b68..be7f3b8 100644 --- a/odsfile.tex +++ b/odsfile.tex @@ -235,6 +235,15 @@ \subsection{Character escaping} \end{tabular} \end{LTXexample} +\subsection{Saving the generated table to a file} + +Use the \texttt{save} option to save the generated table to a file instead of including it directly into the document. + +\begin{LTXexample} +There should be no table listed +\includespread[sheet=List1,columns=head,escape=false,save=save-test.tex] +\end{LTXexample} + \section{Templates}\label{sec:tpl} @@ -413,7 +422,8 @@ \section{Changes} \begin{description} \item [devel] \begin{itemize} - \item added support for multiple ranges in the \texttt{range} option. + \item added the \texttt{save} option + \item added support for multiple ranges in the \texttt{range} option \item added \texttt{newline} and \texttt{lastnewline} options \end{itemize} \item[v0.8]