JS export excel file to fixed network location (folder)

Hi Experts,

I've been using a JS export code that allows me to take data that is being passed from my dashboard and exported as a new excel file (xls).  The export function allows you to save the name of the file, and sheet name.  All this is great.  What I am needing help on is how can we programmatically save the exported file to a pre determined folder (network drive)?  I am not familiar with JavaScript so any assistance would be greatly appreciated.  

This is a request that will give executives the ability to click on a report used for certifying data and have to only hit "Certify" and the csv is placed in a network drive (folder) and the executives will never have to do anything other than hit the certify button. The problem with my code now is that it saves on the local machine as a default.

https://github.com/jmaister/excellentexport

Thanks!  
Attached
excellentexport.js
Maliki HassaniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technical NinjaCommented:
Hi Maliki,


You can not do it via native JavaScript features and using FileSystemObject (VBS/JS) https://msdn.microsoft.com/en-us/library/aa242706(v=vs.60).aspx might not be a good idea but I think that is the only way to go about it.

The location of newly generated file is fixed? I guess not. So that's another challenge. If you can force your users to store the file on a specific location on their systems we might be able to use FSO to move file to a network location.

You can also exploring persistent storage to store the file in WebStorage https://www.w3schools.com/html/html5_webstorage.asp

So basically, user clicks Certify -> file is generated -> Force user to save it on Desktop- for example-> use FSO to move file to a network location.

Regards,
Chinmay.
0
Maliki HassaniAuthor Commented:
Thanks for the details. I think you are right about the FSO.  The html data save wont be a good solution.  

For FSO, any idea how this can be implemented with the existing code?
0
Chinmay PatelChief Technical NinjaCommented:
Could you first check if you are able to create FSO first. I believe most of the environments restrict its usage.
Once we know it is working, we can call MoveFile method, https://msdn.microsoft.com/en-us/library/aa265335(v=vs.60).aspx, after your script has created and stored the file.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Maliki HassaniAuthor Commented:
Will check, thanks.
0
Maliki HassaniAuthor Commented:
Good news, ran the VBScript from local and it created the file on our network drive.  Please let me know next steps.
0
Chinmay PatelChief Technical NinjaCommented:
Sure. In your HTML page where you have those links to generate file, instead of directly calling the file generation link,

call this function
function ProcessFile(params)
{
// params are optional, I am not sure how you are generating the file.
GenerateFile(params); 

// Because we don't know how long it will take the user to click and save the file, we will use a hack
// We might have to change to SetInterval as well
// Let's first try setTimeout
window.setTimeout( function() { MoveFile(params); }, 5000);
}

function GenerateFile(params)
{
alert("Generated Excel");
// from your existing JS code, generate the code
}

function MoveFile(params)
{
// params are optional
// code to move the file to network location
alert("Moved File");
}

Open in new window


I have not tested the code, please adjust it in case you run syntax errors. If it does not work at all, do let me know.

Regards,
Chinmay.
0
Maliki HassaniAuthor Commented:
Thanks Chinmay. What happens when multiple users are certifying?  How does the code accommodate this? Meaning are we hard coding the folder where a single user is downloading to their local machine and the move function moves It?  Each user has an alias name to their local machine. Will we need to get their network ID and pass as a variable?

Thanks!
0
Maliki HassaniAuthor Commented:
Continuation of my thought. Is there any way to execute the saving of the file in a temp folder and have that as the location of the pick up file to be moved? This would need to be executed without user awarnes. The goal is have executives only click one time throughout this process. I know this is quite challenging.

Here is a second and third option for javascript ..

One: is it possible to have a dialog box open after exporting with the network path that the user can select and copy. Basically a reminder of where the file goes?

Two: a dialog box that is similar to the typical download file pop up. Instead ours will have the location already set, the user just needs to hit okay. I gues this would be a custom userform?

I am at your mercy here so please let me know. :)
0
Maliki HassaniAuthor Commented:
I was talking to the security team and it isn't advised to create a move it function.  There is a move it job process through IT that is a approved.  So I guess that leaves us to my suggested option for one and two.
0
Chinmay PatelChief Technical NinjaCommented:
I almost missed your first comment. I was thinking - ask your users to save the file on Desktop only. Then using VBS we can figure out desktop path and filename - as we generated it, we would already have it - and use this info to move our file.

So it does not matter how many users are certifying as long as we can execute VBS we are home.

Yeah :) I was worried about it as well. Thing is you can not do it without user's input. No matter what you do. That power resides with Applications/Batch Files/ActiveX(VBS/JS)/Windows Service. A browser can not download a file without user's acceptance. The web related files which gets downloaded - are taken to a Temp folder BUT then they are HTML/JS etc and cannot interact on their own with other system components.

Suppose we figure out a way to do this, eventually it will be disabled. And I do not have means/capabilities to figure out a loophole that can allow us to download the file.

Now, coming to the problem at hand, how about using your web server to do something about this. Is your web server on your Corporate network? or it is on Internet? This HTML page you are talking about - how it is generated?


Both the options you have suggested - we will be at the mercy of the end users. We  cant force anything unless we use ActiveX - VBScript or JScript (It is different than JavaScript).

Regards,
Chinmay.
0
Maliki HassaniAuthor Commented:
Thanks for the clarity it helps me to understand voice back these challenges.

The web server is on corporate network. As for the generation, we have Tableau dashboards published to Tableau server.  We are using JS and HTML to host a reporting portal.  We are using Tableau's javascript api and jquery to make an array of the data and then using the export code (attached) it presents the download dialog (save file) to the user.

I don't have a problem with a user saying yes to download but it needs to go the correct path and not have a move it job.  If this can't work I was thinking of just having a pop up which will show the network path so that the user can past into the "save as" location path.
0
Chinmay PatelChief Technical NinjaCommented:
How about copying the necessary path in user's clipboard? say for example, after the user generates the file, you can build the network path and then using https://clipboardjs.com/ you can set the path in clipboard. After that you can  simply display an alert stating the path is already copied in your clipboard.

There are many JavaScript libraries available that can show nice dialogs in case you don't want to use out of the box one.
0
Maliki HassaniAuthor Commented:
That would be perfect but does this require installing on the eeb server? If so, i dont eant to go doen that path as its not an easy implementation to make changes in our enviroments. Can you provide an example so i can test?
0
Chinmay PatelChief Technical NinjaCommented:
These are changes which has to be made to the web page. You can download the zip of Clipboardjs and copy the file/s in your web server. Installation is only needed if you are using NPM.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>function-text</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../dist/clipboard.min.js"></script>
</head>
<body>
    <button class="btn">Save File</button>
    <script>
        // Write your Excel generation code here
        // Generate the path and store it in say var targetPath
        var targetPath = "\\\\Networkshare\\"
    var clipboard = new Clipboard('.btn', {
        text: function() {
            return targetPath;
        }
    });

    clipboard.on('success', function(e) {

        console.log(e);
    });

    clipboard.on('error', function (e) {
        // You might warn end users here that Path is not copied to the clipboard
        console.log(e);
    });
    </script>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Maliki HassaniAuthor Commented:
Thanks will implement and let you know. Appreciate your assistance !
0
Maliki HassaniAuthor Commented:
Thanks for the assistance and guidance
0
Chinmay PatelChief Technical NinjaCommented:
Anytime.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.