summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-09-23 23:36:30 +0000
committerKarl Berry <karl@freefriends.org>2015-09-23 23:36:30 +0000
commitdc9643d7d269a0d9153ee8dc2983009c9c0ddbc8 (patch)
tree8ec9fdefcbc812373d416cda5ab30c7831163255
parent9e8df486903c5e9c134230909b411a1a05cb782d (diff)
odsfile (23sep15)
git-svn-id: svn://tug.org/texlive/trunk@38449 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdfbin251598 -> 253761 bytes
-rw-r--r--Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex42
-rw-r--r--Master/texmf-dist/doc/lualatex/odsfile/pokus.odsbin7533 -> 15481 bytes
-rw-r--r--Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua43
-rw-r--r--Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty30
5 files changed, 97 insertions, 18 deletions
diff --git a/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf b/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
index b4dafe00be2..3aaee3587b1 100644
--- a/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
+++ b/Master/texmf-dist/doc/lualatex/odsfile/odsfile.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex b/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
index a3a3c8d486a..cf2d141f6a7 100644
--- a/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
+++ b/Master/texmf-dist/doc/lualatex/odsfile/odsfile.tex
@@ -5,7 +5,7 @@
\author{Michal Hoftich (\url{michal.h21@gmail.com})}
\title{The \textsf{odsfile} package:\\
accessing of the \textsf{opendocument spreadsheet} from \LaTeX{}
-documents\thanks{Version 0.4, last revisited 2014-12-11.}
+documents\thanks{Version 0.6, last revisited 2015-09-20.}
}
\usepackage[english]{babel}
\lstloadlanguages{[LaTeX]Tex}
@@ -63,13 +63,22 @@ Options are:
\begin{description}
\item[file] Filename of file to be loaded. You should specify this only on first use of \cmd{\includespread}.
-\item[sheet] Name of sheet to be loaded. If it's not specified on first use of \cmd{\includespread}, then first sheet from the file is loaded. The sheet remains selected until another use of |sheet|.
+\item[sheet] Name of sheet to be loaded. If it's not specified on first use of
+ \cmd{\includespread}, then first sheet from the file is loaded. The sheet
+ remains selected until another use of |sheet|.
+
\begin{LTXexample}
\begin{tabular}{l l}
\includespread[file=pokus.ods,sheet=List2]
\end{tabular}
\end{LTXexample}
-\item[range] Selects range from table to be inserted. Range is specified in format similar to spreadsheet processors, like |a2:c4|, selecting cells starting at first column, second row and ending and third column, fourth row.
+
+\item[range] Selects range from table to be inserted. Range is specified in
+ format similar to spreadsheet processors, like |a2:c4|, selecting cells
+ starting at first column, second row and ending and third column, fourth row.
+ Other variant of supported ranges are \textit{named ranges}, which can be
+ saved in the |ods file|.
+
\begin{LTXexample}
\begin{tabular}{lll}
\includespread[sheet=List1,range=a2:c4]
@@ -162,8 +171,19 @@ number is the position of the cell from beginning of the selection.
\begin{LTXexample}
\includespread[range=a2:b,rowseparator={,\ },rowtemplate={\textit{-{1}}:-{2}}]
\end{LTXexample}
+
+\item[multicoltemplate]
+supports merged cells. Default template uses left aligned \verb|\multicolumn|
+command
+\begin{LTXexample}
+ \begin{tabular}{lll}
+ \includespread[sheet=Sheet3, multicoltemplate={\multicolumn{-{count}}{r}{-{value}}}]
+ \end{tabular}
+\end{LTXexample}
+
\end{description}
+
\section{Templates}\label{sec:tpl}
If you don't want to specify tabular environment by hand, you can use simple templating mechanism to insert tabular environment by hand.
@@ -339,6 +359,22 @@ CC & 5 & 7
\section{Changes}
\begin{description}
+
+\item[v0.6]
+ \begin{itemize}
+ \item Fixed bug in handling of rows with only one cell\footnote{Thanks to Ulrike Fisher}
+ \item Added support for named ranges
+ \item Fixed text:s handling. Beware that using multiple formatting styles
+ in one cell may result in discarding whole cell, or wrong order. This is
+ caused by underlying LuaXML library and it is likely to remain.
+\end{itemize}
+\item[v0.5]
+\begin{itemize}
+ \item Fixed bug: cell attributes weren't saved
+ \item Added support for merged cells
+ \item Added \texttt{multicoltemplate} option
+\end{itemize}
+
\item[v0.4]
\begin{itemize}
\item Fixed bugs in loading sheets without ranges
diff --git a/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods b/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods
index d2c6762ffba..e59b8762151 100644
--- a/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods
+++ b/Master/texmf-dist/doc/lualatex/odsfile/pokus.ods
Binary files differ
diff --git a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
index ffd47229aca..5017b7bc161 100644
--- a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
+++ b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua
@@ -1,8 +1,9 @@
module(...,package.seeall)
require "zip"
-xmlparser = require ("luaxml-mod-xml")
-handler = require("luaxml-mod-handler")
+local xmlparser = require ("luaxml-mod-xml")
+local handler = require("luaxml-mod-handler")
+local namedRanges = {}
function load(filename)
local p = {
@@ -36,6 +37,9 @@ function getTable(x,table_name)
row = {}
row["_attr"] = r["_attr"]
local cc = r["table:table-cell"] or {}
+ if #cc == 0 then
+ cc = {cc}
+ end
local columns = {}
--for j = 1, #cc do
@@ -65,6 +69,7 @@ end
function getTable0(x,table_name)
local tables = x.root["office:document-content"]["office:body"]["office:spreadsheet"]["table:table"]
+ namedRanges = loadNameRanges(x, table_name)
if #tables > 1 then
if type(tables) == "table" and table_name ~= nil then
for k,v in pairs(tables) do
@@ -93,6 +98,32 @@ function getColumnCount(tbl)
return x
end
+function loadNameRanges(root, tblname)
+ local tblname = tblname or ""
+ local t = {}
+ local ranges = root.root["office:document-content"]["office:body"]["office:spreadsheet"]["table:named-expressions"]
+ if not ranges then return {} end
+ ranges = ranges["table:named-range"] or {}
+ if #ranges == 0 then
+ ranges = {ranges}
+ end
+ for _,r in ipairs(ranges) do
+ local a = r["_attr"] or {}
+ local range = a["table:cell-range-address"] or ""
+ local name = a["table:name"]
+ if name and range:match("^"..tblname) then
+ range = range:gsub("^[^%.]*",""):gsub("[%$%.]","")
+ print("named range", name, range)
+ t[name] = range
+ end
+ end
+ return t
+end
+
+
+
+
+
function tableValues(tbl,x1,y1,x2,y2)
local t= {}
local x1 = x1 or 1
@@ -106,8 +137,9 @@ function tableValues(tbl,x1,y1,x2,y2)
if #v["table:table-cell"] > 1 then
local r = table_slice(v["table:table-cell"],x1,x2)
for p,n in pairs(r) do
+ local attr = n["_attr"]
local cellValue = n["text:p"] or ""
- table.insert(j,{value=cellValue,attr=att})
+ table.insert(j,{value=cellValue,attr=attr})
end
else
local p = {value=v["table:table-cell"]["text:p"],attr=v["table:table-cell"]["_attr"]}
@@ -120,6 +152,7 @@ function tableValues(tbl,x1,y1,x2,y2)
end
function getRange(range)
+ local range = namedRanges[range] or range
local r = range:lower()
local function getNumber(s)
if s == "" or s == nil then return nil end
@@ -179,7 +212,6 @@ function escape(s)
return string.gsub(s, "([#%%$&])", "\\%1")
end
-
function get_cell(val, delim)
local val = val or ""
local typ = type(val)
@@ -191,7 +223,8 @@ function get_cell(val, delim)
elseif val["text:span"] then
return get_cell(val["text:span"], delim)
elseif val["text:s"] then
- return get_cell(val["text:s"], delim)
+ -- return get_cell(val["text:s"], delim)
+ return table.concat(val, " ")
else
local t = {}
for _,v in ipairs(val) do
diff --git a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
index 57a2be71952..97f9e0d9c61 100644
--- a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
+++ b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty
@@ -3,14 +3,15 @@
%keyval keys
-\define@key{includespread}{file}{\loadodsfile{#1}}
-\define@key{includespread}{sheet}{\luaexec{sheetname = "\luatexluaescapestring{#1}"}}
+\define@key{includespread}{file}{\loadodsfile{#1}}%
+\define@key{includespread}{sheet}{\luaexec{sheetname = "\luatexluaescapestring{#1}"}}%
\define@key{includespread}{range}{\luaexec{%
local x1,y1,x2,y2 = odsreader.getRange("\luatexluaescapestring{#1}")%
range = {x1,y1,x2,y2}%
}}
\define@key{includespread}{template}{\luaexec{currenttemplate="\luatexluaescapestring{#1}"}}%
\define@key{includespread}{rowtemplate}{\luaexec{rowtemplate="\luatexluaescapestring{\unexpanded{#1}}"}}%
+\define@key{includespread}{multicoltemplate}{\luaexec{multicoltpl="\luatexluaescapestring{\unexpanded{#1}}"}}%
\define@choicekey*+{includespread}{rowseparator}[\val\nr]{tableline,hline,newline}[tableline]%
{%
@@ -27,10 +28,10 @@ rowseparator=[[\\n]]
\luaexec{rowseparator="\luatexluaescapestring{#1}"}
}
\define@key{includespread}{columnbreak}{%
- \luaexec{columnbreak="\luatexluaescapestring{\unexpanded{#1}}{}"}
+ \luaexec{columnbreak="\luatexluaescapestring{\unexpanded{#1}}{}"}%
}
\define@key{includespread}{coltypes}{%
- \luaexec{coltypes="\luatexluaescapestring{\unexpanded{#1}}"}
+ \luaexec{coltypes="\luatexluaescapestring{\unexpanded{#1}}"}%
}
\define@choicekey*+{includespread}{columns}[\val\nr]{head,top,none}{%
\ifcase\nr\relax%
@@ -64,7 +65,8 @@ row = {}
body = nil
odsfilename = ""
currenttemplate = nil
-rowtemplate=nil
+rowtemplate = nil
+multicoltpl = "\\multicolumn{-{count}}{l}{-{value}}"
\end{luacode*}
\newcommand\loadodsfile[2][]{%
@@ -78,7 +80,7 @@ rowtemplate=nil
\newcommand\tabletemplate[2]{%
\luaexec{%
- templates["#1"]="\luatexluaescapestring{\unexpanded{#2}}"
+ templates["#1"]="\luatexluaescapestring{\unexpanded{#2}}"%
}
}
@@ -110,11 +112,17 @@ rowtemplate=nil
local t={}
local i = 1
for _,column in pairs(row) do
+ local attr = column.attr or {}
local value, br = concatParagraphs(column.value)
value = value or ""
+ local x = attr["table:number-columns-spanned"] or "1"
+ x = tonumber(x)
+ if x > 1 then
+ value = odsreader.interp(multicoltpl, {value = value, count = x})
+ end
table.insert(t,value)
headings[i] = br
- i = i + 1
+ i = i + x
end
return t, headings
end
@@ -177,10 +185,12 @@ rowtemplate=nil
table.insert(content,odsreader.interp(rowtemplate,rowValues(row)))
end
content = table.concat(content,rowseparator)
- tex.sprint(odsreader.interp(templates[currenttemplate],{content=content}))
+ local result = odsreader.interp(templates[currenttemplate],{content=content,coltypes=coltypes,colheading=colheading,rowsep=rowseparator})
+ print(result)
+ tex.sprint(result)
end
- }
-}
+ }%
+}%
\tabletemplate{empty}{-{content}}