This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

CSV report
#1
I have script, bun I need to select values in two different group address ranges. From 1 to 15 and from 20 to 30.
I need get the values in one csv file.

rows = {}
 
-- from 3/0/1 to 3/0/30
addrstart = 1
addrend = 190
 
rows[ #rows + 1 ] = 'name,actual_value,start_month,current_month,previous_month'
 
for i = addrstart, addrend do
  actual_value_obj = grp.find('3/1/' .. i)
  name = actual_value_obj.name
  actual_value = actual_value_obj.value
  start_month = grp.getvalue('2/1/' .. i)
  current_month = grp.getvalue('4/1/' .. i)
  previous_month = grp.getvalue('1/1/' .. i)
 
  rows[ #rows + 1 ] = name .. ',' .. actual_value .. ',' .. start_month .. ',' .. current_month .. ',' .. previous_month
end
 
--csv = table.concat(rows, '\r\n')
csv = string.char(0xEF, 0xBB, 0xBF) .. table.concat(rows, '\r\n')
 
-- read csv report file
--data = storage.get('csv')
to1 = grp.getvalue('7/7/2')
to2 = grp.getvalue('7/7/7')
date = os.date('%Y-%m-%d')
 
 
 
-- send file as report.csv with text/csv mime type
res, err = mailattach('Atskaite par tekoso menesi', 'CSV file attached', 'report-1-90' .. date .. '.csv', csv, 'text/csv')
Reply
#2
Code:
rows = { 'name,actual_value,start_month,current_month,previous_month' }

function pushrow(i)
  local actual_value_obj = grp.find('3/1/' .. i)
  local name = actual_value_obj.name
  local actual_value = actual_value_obj.value
  local start_month = grp.getvalue('2/1/' .. i)
  local current_month = grp.getvalue('4/1/' .. i)
  local previous_month = grp.getvalue('1/1/' .. i)

  rows[ #rows + 1 ] = name .. ',' .. actual_value .. ',' .. start_month .. ',' .. current_month .. ',' .. previous_month
end

-- from 3/1/1 to 3/1/15
for i = 1, 15 do
  pushrow(i)
end

-- from 3/1/20 to 3/1/30
for i = 20, 30 do
  pushrow(i)
end

--csv = table.concat(rows, '\r\n')
csv = string.char(0xEF, 0xBB, 0xBF) .. table.concat(rows, '\r\n')
Reply
#3
Thanks. All OK
Reply


Forum Jump: