How do I append results of text boxes to a local excel file

Get help using Construct 2

Post » Sun Jan 10, 2016 4:03 am

I have a layout with several text boxes and drop down menus as well as a submit button. How would I go about setting up the event sheet to send all the data from those fields to an excel spreadsheet that could be appended each time I filled out the form?

Also, is there a way to open the contents of that file from within another layout?
B
7
Posts: 16
Reputation: 307

Post » Sun Jan 10, 2016 8:53 am

https://en.wikipedia.org/wiki/Microsoft ... le_formats

Try formatting your data into an xml spreadsheet that looks like the one on the site (just with your data and layout).
How you could go about this?
(I only have Libre Office, so I am using this):

1) open LibreOffice Calc
2) fill your Layout. The fields that should be filled with your data later on, you can fill with a unique placeholder. Let's say you use %sub1%, %sub2%, %sub3% and so on for different fields. Now you save that as Excel 2003 xml. You should see a format similar to the one on the linked webpage.
3) Load the file contents into your construct 2 project. (add to project files, request the project file with ajax -> save the contents into a variable; or if you want to, you could also skip the adding of the file to the project files and copy the contents of the file from a text editor to a variable and be done with it; care: you'd need to replace all " to ' in the xml-file)
4) Now to filling those values: use the replace function. Say your value for %sub1% is "foo" Then you would do: replace(filecontents, "%sub1%", "foo")
5) use the Browser object and invoke download of a string, string = filecontents, mimetype = "application/xls", filename = "yourexcelfile.xls"
done

example:
Image
https://copy.com/v34AQljxsEd371u6


Opening the contents from that file from another layout can be done with regex, but it will require knowledge of regex (the more complex the file is, the more difficult it will be).
If it's the same project and you expect the person to open it on the same computer, maybe you could use local storage. Or you put your data into an array and save the array as json (browser string download again) as a second file for the user. This could be loaded very easily into another project through the load json expression.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sat Feb 13, 2016 1:32 pm

Hi @mindfaQ,

This was just what I have been looking to do for dinner time. Thanks :)

Do you think this would work on mobile? First year failed but will try again when I can (I tried webview cocoonio).

Cheers
B
37
S
10
Posts: 188
Reputation: 3,818


Return to How do I....?

Who is online

Users browsing this forum: imhotep22, pcprice76, winon, Xh3maa and 2 guests