Upload Excel File and save it as CSV to a specified path

426 Views Asked by At

I'm new to Mendix and need to solve the following:

Users all over the world drop a file (xlsx or xls) onto a web page or select a file through a file dialog. This file should be stored - converted to CSV - with a self-specified name onto a specified share on an own server.

We've puzzled for hours - but to no avail...

We tried various ExcelImporter-templates, the Export_to_CSV-button and several ready-cooked templates in the hope to understand the principles. Besides various obstacles the final problem was to get the file on our own machine.

Is there anybody who can point to the needed widgets and who can explain (sort of a cooking recipie :-) ) how to proceed?

TIA

1

There are 1 best solutions below

1
On BEST ANSWER

Where are you expecting the file to end up? By importing or creating the export it automatically makes a file that is stored on your machine, it's a question of how you want to get it out. You can access the files by building a page and having the file manager widget on it, or you could pass it back through the browser by using the 'Download file' activity in your original import/export microflow.

Then there are options of writing it to a specific directory on your machine or through (s)ftp, which I have seen most often. For ftp you can use this: https://marketplace.mendix.com/link/component/106858

If you want to write it to a specific directory on the machine I would recommend a very basic Java action, pass your FileDocument entity into that action. I like apache commons IO, which is in many modules already, then the code would be just this:

File outputFile = new File(this.OutputPathParameter + "output.csv"); FileUtils.copyInputStreamToFile(Core.getFileDocumentContent(this.getContext(), this.FileDocParameter), outputFile);

Also I would recommend asking Mendix dev questions on forum.mendix.com there are a lot of people on there who very quickly answer your questions.