0

I'm doing python coding self study and not a programmer.. this is my first entry here. Not sure if this is doable, (I have a very little knowledge about programming) but here it is.

Is it possible to insert a file, like a template, for the user to download in a standalone program? Tried searching online but have not been successful, maybe I just don't know how to term it.

Any suggestion is very welcome.. thanks in advance..

When user clicks 'Download template', they can download an Excel template

User can download the template that I inserted in a program, that is if inserting file in a standalone program is possible.

la_mun
  • 5
  • 3

1 Answers1

0

I think what you are asking is if you can embed a file into the .py itself (which is what I think you mean when you are saying standalone), to which the answer is no. It might be possible to compile the program into an exe using pyinstaller, but not sure how efficient or feasible that is.

If you really need this to be only one .py, I would suggest hosting it somewhere online for free and having python download the file from the url.

If I am being honest, the best way to go about doing this is to ditch the "standalone program" requirement and just shipping the template in a zip file with the .py file.

Edit: Creating the file on-demand

This slipped my mind as an idea (probably because it is the most involved and difficult way to do it), but you may be able to use something like XSLX writer to create the excel file on demand. Would require you to code a function that makes a brand new excel file from scratch, but this would not require downloads, zip files, or an executable, so it would be truly standalone (minus the added pip dependency).

Be warned though, I think python and XLSX can be finicky at times.

sami-amer
  • 254
  • 3
  • 9
  • thanks for the suggestion.. will consider it. another lesson to study.. – la_mun Dec 17 '22 at 02:36
  • Always more to learn! If you feel like the question was answered, please accept the answer (if you want to leave it open for more answers, this is also great; just want to make sure the question does not remain dormant if you consider it done) – sami-amer Dec 17 '22 at 02:38
  • I'm still having a hard time navigating the comments section and on how to reply and to make mentions.. thanks so much.. – la_mun Dec 17 '22 at 02:41
  • thank you for the suggestion.. i did what u suggested and created a generate template function but in a very simple code as i only want to create an excel template with only the first two rows populated, header and sample entries. – la_mun Dec 17 '22 at 03:18