summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
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 /Master/texmf-dist/tex
parent9e8df486903c5e9c134230909b411a1a05cb782d (diff)
odsfile (23sep15)
git-svn-id: svn://tug.org/texlive/trunk@38449 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua43
-rw-r--r--Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty30
2 files changed, 58 insertions, 15 deletions
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}}