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/odsfile/odsfile.lua | |
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/odsfile/odsfile.lua')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/odsfile/odsfile.lua | 100 |
1 files changed, 95 insertions, 5 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 {}) |