Skip to content

how to split CSV data? #404

Answered by pgundlach
pr-apes asked this question in Q&A
Jul 14, 2022 · 3 comments · 1 reply
Discussion options

You must be logged in to vote

Not sure if I understand it correctly and I am not sure if this is really a speedata Publisher issue, but you can try something like this:

csv = require("csv")
xml = require("xml")

csvtab, msg = csv.decode("data.csv")
if not csvtab then
    print(msg)
    os.exit(-1)
end

dofile("debug.lua")

local datatab

local datacounter = 0

for i=1,#csvtab do
    local has_value = false
    local val = {}
	for j=1,#csvtab[i] do
		val[#val+1] = {_name = "cell", csvtab[i][j]}
        if csvtab[i][j] ~= "" then has_value = true end
	end

    if not has_value or i == #csvtab then
        if datatab then
            datacounter = datacounter + 1
            ok, err = xml.encode_table(datatab,string.format(

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@pr-apes
Comment options

Answer selected by pr-apes
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants