How do I write to excel and have images

Get help using Construct 2

Post » Fri Sep 16, 2016 5:10 pm

My trouble is getting the image into an excel output rather than into my app. I think i need to work out of its possible to export data into an .cos file rather than .xml template which is my apps current method.
B
38
S
11
G
1
Posts: 201
Reputation: 4,469

Post » Fri Sep 16, 2016 6:20 pm

Closer to what you want look at xlsx files. They are zip files of xml files and other things like images.

You could use something like this to manipulate the zip file from js
https://stuk.github.io/jszip/

Then either by looking at the file format spec or disecting some simple xlsx files it should be possible to see how it's done. You could also look at some xlsx JavaScript library but I'm not sure images work with them.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Sat Sep 17, 2016 7:13 am

Thanks @R0j0hound. Looks like some lessons in javascript / C2 pluggin making for me. Shame my programming is as primitive as Spectrum ZX basic!

10 CLS
20 Print "Help!"
30 Goto 20

:roll:
B
38
S
11
G
1
Posts: 201
Reputation: 4,469

Post » Mon Sep 19, 2016 9:52 pm

@Mayfly
This is actually a very difficult thing to do.

Looks like the only js library that can do it is this:
http://excelbuilderjs.com/

Here's an example of it's use from C2 with the browser object.
https://dl.dropboxusercontent.com/u/542 ... excel.capx

First it loads the needed libraries and call the "ready" function when it's done.
Next it creates the workbook, worksheet and populates it from a 2d javascript array.
Then to get a image to save it snapshots the canvas. You could use the canvas object to get image data as well.
Finally it generates the file and uses the browser object to download it.

It basically follows the examples on their site and at the very least gives you a starting point to play around with. Also I won't be making a plugin for this.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Tue Sep 20, 2016 6:23 pm

@R0j0hound
As usual a great help :) Had a very quick load and play. That's just what I was pretty much after so I'll have a mess about in terms of getting that working how I am after. Should be able to take it from there / integrate into my app. BIG thanks!
B
38
S
11
G
1
Posts: 201
Reputation: 4,469

Post » Tue Nov 01, 2016 5:37 pm

@R0j0hound

Had a play around and think I could get this working. Unluckily for me it would mean re-writing quite a bit of my program to get working. Also my current program loads in a pre-made .xml file and does a 'replace' of certain headings / values. It actually works really well as it keeps heading formatting (Colours / fonts etc..)

It just lacked the ability to save as a proper excel file / support pictures. Maybe I can 'merge' the two ideas together so I can load up a pre made .xlsx file and update the text in certain places / append a photo.

I've attached an example capx below which shows very simply how my app runs. (Two files in the project, the xml file which is used and works and an xlsx file which I have been unable to get working which contains a shape as a picture reference).

https://drive.google.com/open?id=0B33gt ... WRXZEhqeUE

Thanks,
B
38
S
11
G
1
Posts: 201
Reputation: 4,469

Post » Mon Nov 07, 2016 6:25 pm

That's more than I'm willing to help with. The library I used can't load excel files, but it's the only one I found that can add images.

Anyways I guess a way to do it would be to take the xml file, do your replacements, then use the xml plugin to access all the data in it. Finally it's a matter of transferring it all over to a format the excel js library can use to create the file. At a glance it should support all the features you need but maybe not. It'll be a lot of digging to get it working either way.
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Previous

Return to How do I....?

Who is online

Users browsing this forum: darkrealos, plinkie, Rhindon and 20 guests