Skip to content

Commit

Permalink
Added the save option
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-h21 committed Apr 24, 2024
1 parent 11639f1 commit 4b61a42
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 7 additions & 0 deletions odsfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
19 changes: 17 additions & 2 deletions odsfile.sty
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"}%
}
Expand Down Expand Up @@ -74,6 +79,7 @@ range = {nil,nil,nil,nil}
columns = nil
templates = {}
row = {}
odssave = nil
body = nil
odsfilename = ""
currenttemplate = nil
Expand Down Expand Up @@ -119,6 +125,7 @@ odslastnl = "\\OdsLastNl"
rowseparator = ""
columns=nil
currenttemplate = nil
odssave = nil
rowtemplate = nil
celltpl = "-{value}"
columnbreak = "\\linebreak{}"
Expand Down Expand Up @@ -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"
Expand All @@ -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
}%
}%
Expand Down
12 changes: 11 additions & 1 deletion odsfile.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 4b61a42

Please sign in to comment.