Hi there,
I am doing a script which writes in a CSV value and name of a list of object selected by a tag.
Since the script is launched with a push button, I am wondering if It Is possibile download the file CSV directly on the browser. I mean such as trend log file push button export.
You can use .lp file to generate a CSV that will be sent to the user.
First you need to attach an event to a button that will open .lp in a new window:
<?
-- set headers for csv file downloadsetdlheader('text/csv; charset=utf-8', 'report', 'csv')
-- generate csv here csv = '...'-- output to the userprint(csv)
(20.11.2020, 06:57)admin Wrote: You can use .lp file to generate a CSV that will be sent to the user.
First you need to attach an event to a button that will open .lp in a new window:
<?
-- set headers for csv file downloadsetdlheader('text/csv; charset=utf-8', 'report', 'csv')
-- generate csv here csv = '...'-- output to the userprint(csv)
Hi admin,
sorry but do not understand program language above. If I use <? LM inform me "Lua syntax error at line 1: unexpected symbol near '<'".
.lp file is not a script, it's a Lua file that only the web server can run. It should be uploaded via FTP to the user directory using apps username. If the file is named csv.lp then the URL will be http://LM_IP/user/csv.lp
(24.11.2020, 07:34)admin Wrote: .lp file is not a script, it's a Lua file that only the web server can run. It should be uploaded via FTP to the user directory using apps username. If the file is named csv.lp then the URL will be http://LM_IP/user/csv.lp
Code:
1234567891011121314151617181920212223242526
<?
-- set headers for csv file downloadsetdlheader('text/csv; charset=utf-8', 'report', 'csv')
-- generate csv here value=grp.tag("consumption")
filename = string.format('consumption.csv', os.date('%d-%m-%Y-%H-%M'))
a={}
forindex, idinipairs(value) doname=id["name"]
meter=id["data"]
consumption=name .."," .. metera[index]=consumilog(a)
endcsv = aresult, err = io.writefile (filename, csv)
-- output to the userprint(csv)
I generate file as above without success. Is it correct the procedure? Thanks.
<?
require('apps')
-- set headers for csv file downloadsetdlheader('text/csv; charset=utf-8', 'Consumption', 'csv')
-- generate csv here value=grp.tag("consumption")
a={}
forindex, idinipairs(value) doname=id["name"]
meter=id["data"]
consumption=name .."," .. metera[index]=consumiendprint(a)
Thank you very much Admin, but unfortunately when I launch the script on the visu I receive response from http://192.168.1.10/user/csv.lp that it is not possible reach the web site. The script is correct and I cannot identify the problem.
With this above I would like to replace dot with comma in the number. I do not know why but he replace all the number with ",". Hence 23.88 became ,,,,,