diff options
author | Karl Berry <karl@freefriends.org> | 2014-12-12 00:31:32 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2014-12-12 00:31:32 +0000 |
commit | ced32a1c9de464097273dc6e37892d7380c55d85 (patch) | |
tree | 68fcda0a7e1bad71a18ed8e19423862675036c73 /Master/texmf-dist/tex/lualatex | |
parent | 1c0ada95b9f2e2d9dd151cf8d8487f9430ff1db9 (diff) |
odsfile (11dec14)
git-svn-id: svn://tug.org/texlive/trunk@35791 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/lualatex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua | 100 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty | 29 |
2 files changed, 117 insertions, 12 deletions
diff --git a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua index d305fb48a5f..406700b9b3a 100644 --- a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua +++ b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua @@ -22,10 +22,52 @@ function load(filename) end function getTable(x,table_name) + local t = getTable0(x,table_name) + local t2 = {} + + for key, val in pairs(t) do + if key == "table:table-row" then + local rows = {} + + for i = 1, #val do + local r = val[i] + local rowRep = r["_attr"]["table:number-rows-repeated"] or 1 + + row = {} + row["_attr"] = r["_attr"] + local cc = r["table:table-cell"] or {} + + local columns = {} + --for j = 1, #cc do + -- local c = cc[j] + for _, c in ipairs(cc) do + c["_attr"] = c["_attr"] or {} + local colRep = c["_attr"]["table:number-columns-repeated"] or 1 + for k = 1, colRep, 1 do + table.insert(columns, c) + end + end + row["table:table-cell"] = columns + + for j = 1, rowRep, 1 do + table.insert(rows, row) + end + end + + t2[key] = rows + else + t2[key] = val + end + end + + return t2 +end + +function getTable0(x,table_name) local tables = x.root["office:document-content"]["office:body"]["office:spreadsheet"]["table:table"] if #tables > 1 then if type(tables) == "table" and table_name ~= nil then - for k,v in pairs(tables) do + for k,v in pairs(tables) do if(v["_attr"]["table:name"]==table_name) then return v, k end @@ -40,8 +82,22 @@ function getTable(x,table_name) end end +function getColumnCount(tbl) + local tbl = tbl or {} + local columns = tbl["table:table-column"] or {} + local x = 0 + for _, c in pairs(columns) do + local attr = c["_attr"] or {} + local rep = attr["table:number-columns-repeated"] or 1 + x = x + rep + end + return x +end + function tableValues(tbl,x1,y1,x2,y2) local t= {} + local x1 = x1 or 1 + local x2 = x2 or getColumnCount(tbl) if type(tbl["table:table-row"])=="table" then local rows = table_slice(tbl["table:table-row"],y1,y2) for k,v in pairs(rows) do @@ -51,12 +107,13 @@ 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 - table.insert(j,{value=n["text:p"] or "",attr=n["_attr"]}) + local cellValue = n["text:p"] or "" + table.insert(j,{value=cellValue,attr=att}) end else local p = {value=v["table:table-cell"]["text:p"],attr=v["table:table-cell"]["_attr"]} table.insert(j,p) - end + end table.insert(t,j) end end @@ -113,6 +170,39 @@ function interp(s, tab) ) end +get_link = function(val) + local k = val["text:a"][1] + local href = val["text:a"]["_attr"]["xlink:href"] + return "\\odslink{"..href.."}{"..k.."}" +end + +function escape(s) + return string.gsub(s, "([#%%$&])", "\\%1") +end + + +function get_cell(val, delim) + local val = val or "" + local typ = type(val) + if typ == "string" then + return escape(val) + elseif typ == "table" then + if val["text:a"] then + return get_link(val) + elseif val["text:span"] then + return get_cell(val["text:span"], delim) + elseif val["text:s"] then + return get_cell(val["text:s"], delim) + else + local t = {} + for _,v in ipairs(val) do + local c = get_cell(v, delim) + table.insert(t, c) + end + return table.concat(t,delim) + end + end +end -- Interface for adding new rows to the spreadsheet @@ -156,9 +246,9 @@ function newRow() local pos = pos or self:findLastRow(sheet) print("pos je: ",pos) if sheet["table:table-column"]["_attr"] and sheet["table:table-column"]["_attr"]["table:number-columns-repeated"] then - table_columns = sheet["table:table-column"]["_attr"]["table:number-columns-repeated"] + table_columns = sheet["table:table-column"]["_attr"]["table:number-columns-repeated"] else - table_columns = #sheet["table:table-column"] + table_columns = #sheet["table:table-column"] end for i=1, table_columns do table.insert(t,self.cells[i] or {}) diff --git a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty index 6ec21d15860..1d7609b981c 100644 --- a/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty +++ b/Master/texmf-dist/tex/lualatex/odsfile/odsfile.sty @@ -1,4 +1,4 @@ -\ProvidesPackage{odsfile.sty} +\ProvidesPackage{odsfile} \RequirePackage{luacode,xkeyval} %keyval keys @@ -9,8 +9,8 @@ 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}{template}{\luaexec{currenttemplate="\luatexluaescapestring{#1}"}}% +\define@key{includespread}{rowtemplate}{\luaexec{rowtemplate="\luatexluaescapestring{\unexpanded{#1}}"}}% \define@choicekey*+{includespread}{rowseparator}[\val\nr]{tableline,hline,newline}[tableline]% {% @@ -18,7 +18,7 @@ range = {x1,y1,x2,y2}% \luaexec{rowseparator=""}% \or% \luaexec{rowseparator="\\hline "}% -\or +\or% \luaexec{% rowseparator=[[\\n]] } @@ -98,10 +98,12 @@ rowtemplate=nil local values = odsreader.tableValues(body,range[1],range[2],range[3],range[4]) %-- Conversion of odsfile table values to LaTeX tabular local concatParagraphs = function(column) + % -- second returned value signalize whether cell contain paragraph, or not + local getCell = odsreader.get_cell if type(column) =="table" then - return table.concat(column, columnbreak), true + return getCell(column, columnbreak), true end - return column, false + return getCell(column,""), false end local rowValues = function(row, headings) local headings = headings or {} @@ -109,6 +111,7 @@ rowtemplate=nil local i = 1 for _,column in pairs(row) do local value, br = concatParagraphs(column.value) + value = value or "" table.insert(t,value) headings[i] = br i = i + 1 @@ -120,7 +123,9 @@ rowtemplate=nil local h = h or {} local p = 0 for _, c in pairs(h) do - if c then p = p + 1 end + if c then + p = p + 1 + end end if p > 0 then local j = {} @@ -225,4 +230,14 @@ row:insert(body,pos)% odsreader.updateZip(odsfilename,"content.xml")% }% } + +% support for hyperlinks in cells + +\newcommand\odslink[2]{\texttt{#2}} + +\AtBeginDocument{% + \@ifpackageloaded{hyperref}{% + \renewcommand\odslink[2]{\href{#1}{#2}}% + }{} +} \endinput |