I am developing an Excel add-in using Office JS in which a user can decide to open a document from a remote server API. In that case I need to receive a file from the server API and open it in Excel.
I already found this answer: Programatically open a excel document using javascript office api
So I see that the API does not allow this, and the answer suggests triggering the download using JS.
So I added an iframe to the addin page:
<iframe id="download" width="1" height="1" style="display:none"></iframe>
And to trigger the document download I am doing:
document.getElementById("download").src = downloadURL;
That works perfectly when trying online (Office 365).
But it is not downloading the document using the desktop version.
How can I make the solution word in desktop Excel application?
Currently, there is no API in Excel to allow you to create/open document programmatically. Word does have it, and there is a suggestion -- currently under investigation-- for doing the same for Excel as well (https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/suggestions/15034512-ability-to-open-replace-workbook-with-excel-js-api). But, there is not ETA that we can share yet.
That being said, you can absolutely pop up a "save as" dialog. In fact, if you've seen Script Lab, our "Export for publishing" does just that.
For Script Lab, we use the FileSaver NPM package. If you want to see the bit of Script Lab code that makes use of it, see this file, searching the area around FileSaver.saveAs. Note, however, that the save-as dialog does not seem to work correctly on Mac or iOS, so at the moment we limited this functionality to just Desktop and Office Online (you can see a platform check towards the beginning of that method).
Hope this helps!
If I'm understanding what you're trying to do, I have a potential solution.
One way to download a file from a URL with minimal coding is via the command-line with the Background Intelligent Transfer Service (BITSAdmin) Tool included with Windows.
This example downloads a cooking chart, in the background, to the location (and filename) you specify:
Sub testDownloadFileFromCMD()
Const source_downloadURL = "http://instantpot.com/wp-content/uploads/2017/08/Cooking-Time-Tables-1.pdf"
Const dest_PathFilename = "C:\downloadedPDFFile.pdf"
Shell ("bitsadmin /transfer wcb /priority high " & source_downloadURL & " " & dest_PathFilename)
End Sub
It shows the progress window but that can be optionally hidden.
Does your URL work with BITS?
If this doesn't work then there are many other ways to download a file but I'll definitely need more information. I'm not sure what you mean by "the API allows Outlook365 but doesn't allow Excel to download the file". Is the API giving an error? More about this file... Is it Text/Binary? What kind of file. Is it large enough that size could be a problem? Are you able to download the file in other ways, like directly with a browser?
I hope this helps and if not I'll have more to say! :-)
Related
The use case of this problem is very simple but i struggle to find a good solution for it.
I want to allow my users (through a webapp) fill some pdf files stored in server (pdf with forms, which begin more and more popular).
Actually, app like chrome or acrobat reader are able to fill them perfectly whe its open locally.
I already allow this functionnality for docx and xlsx files, for that i use Webdav and the custom protocols ms-word ad ms-excel. It works perfectly.
For pdf, I didnt found equivalent. Its look the mains pdf reader/editor doesn't implement this protocol. Whe we open distant file with these tools, they failed for write permission when save or they try to save the file locally) .
Another option i take a look was the new file system access api (https://web.dev/file-system-access/). But again i wasn't able to make it working properly. The main problem here is how we can edit the file.? Im able with this api to dowload the file locally and keep the filehandler to retrieve the updates, but i blocked on how i can edit the file ? like an option on the fileHandler to say "Open this file with default editor on the OS". this would be perfect. But for now to edit the file i have to manually open it on the eplorer. i can't ask my end user to do that there is too many risk they edit the wrong file.
Another option on the table is the different javascript library for editing PDF, but these last one looks all very expensive, usually very heavy on the client side, with advanced features definitively i don't need. I just want to fill the forms and retrieve the pdf completed. So i would like to avoid this option.
Last option i take a look, i already use pdf.js (from mozilla) and pdf-lib.js in my app for some drawing features. I was thinking
rendering the pdf with pdf.js
retrieve all the forms fields (id, type, size, position) of the pdf with pdf-lib
generate html input write on the top of the pdf with the informations given by pdf-lib
i let the users fill the input and click on a save button whe he finished
on the save, i edit my pdf with pdf lib, i set the value of all my forms fields by taking value of the corresponding html input, and i retrieved the pdf updated.
This solution look for me the more "feasible". But im afraid of the volume of development, on how it will render, deal with zoom, rotation, etc. i would like to not have my custom solution.
I precise my webapp target chrome so it make me crazy to not be able to use the chrome pdf viewer/editor to do what i want.
PS : i struggle to post this question on stackoverflow. the previous one was deleted witout i had precise reasons. i try to be more specific on this one, but please if its such a dumb question, please answer it
I feel your pain, this is currently not possible. Adobe acrobat can open PDFs from webdav locations (simply call acrobat.exe and pass in the WebDAV UNC and it will work) but there is no way to trigger this from the browser.
If you are able to deploy software to your customers machines, you could create a custom URL scheme to do this...
I want to open a file in its Windows default application.
Actually, the scenario is as below:
A file is saved in Database and it is shown as a preview in CKEditor
When I double click on that file, it should open in its default application. The file can be a Word or Excel or PDF file
Then the user will edit the file in that default application
And when the user saves that file or closes the document, it should be updated on the server also it should refresh the file preview in CKEditor
I just want to know if there is any way to open the file in its default application.
Things I have tried:
I tried to use the ActiveX object to open the file, but it is not supported in Chrome and Firefox. And anyway, many forums are saying that it is the end of ActiveX era.
Tried to find if there is any CKEditor plugin, but did not find any.
Thank you in advance for your answer.
Short answer: no. Can you imagine the security nightmare if JavaScript was allowed to execute arbitrary binary files on a user's machine?
Your solution is going to be to find a JavaScript library that allows for handling those files, similar to how PDF.js was made for PDFs in-browser.
This is an odd use-case and I've tried to steer the users away from this, but I have a request to load locally stored PPT files in an HTML environment.
The idea is to view the PPT in an iframe so that I can "decorate" all around it. Users will be creating playlists, of sorts, so I need to add "next" and "previous" presnetation buttons, etc.
I have an online version of this working using the Office webapp link that many other posts have shared, but there is a concern for poor connectivity so they want it to be available offline.
My instinct was to shape this up as a PWA. I can make them use Chrome, so I have the FileSystem API "caching" the PPT files from the online source. However, I have no way to render the saved files!
Because it's offline, I can't use googledocs or continue to MS web office.
I don't know the AppCache feature well enough, but wondered if I can preload all of the docs in an iframe, will it cache those. My thought is that it won't, because the content is on microsoft (or Google's) site.
All users will have a legal copy of PPT on the computer, if that helps at all.
So far I have tried storing the files using the filesystem API in combination with the Chrome offline viewer extension and alternatively the Native Docs extension. The Chrome one will allow me to open a doc, but directly in edit mode. I need to simulate the behavior of a ppsx file, but neither extension works with ppsx files and I don't see documentation for an API that will allow me to "auto-play" the presentations.
Thanks for any ideas!
Wayne
I'm trying to add a visual impaired option to an HTML5 based kiosk that runs offline. The idea is that once a a button is clicked each page's text is read out loud (only 1 text box per page which is loaded from external txt file) speak.js seems like an option but the voice quality isn't that great. I had a look at some chrome plug ins but they all require you to select the text first. I'd like to try jTalk but still waiting on a download link from the creator - not sure if that will work anyway as this needs to run locally on the windows 7 pc serving as the kiosk. The chrome plugins seem to work nicely but they all require the text to be selected and I'm not sure how I could control text being read or not via n HTMl/JS link anyway. therefore ideally I'd like a Jscript library that would let me execute the command on a page per page basis.
Any ideas / suggestions?
Thanks!
I think http://www.chromevox.com might have what you are looking for. It's a chrome extension for vision-impaired users and has an api you can use.
I am currently creating a Chrome extension (which uses javascripts mainly) that allows users to scrape the images on a webpage and download them. I have finished the link scraping part, and the code will return an array like:
["http://example.com/image1.jpg","http://example.com/image2.jpg"]
But how do I download all of the links in ONE CLICK? I tried listing all photos on a new tab and let the users to Ctrl+S save the page. But this greatly affects the UI and I do not like it. I do not host webpage so server side script may not be working.. Any other solutions?
As far as I know, Chrome extensions technically can't save files to disk like Firefox.
The only way to do this is using NPAPI
Unfortunately, extensions using npapi will most likely not be accepted by the Web Store due to security problems. Of course it'll be okay if you use it for yourself or host the extension on your website.
You can install and examize the code of the following extensions, maybe you can even use the provided npapi too:
Screen Capture (by Google) https://chrome.google.com/webstore/detail/cpngackimfmofbokmjmljamhdncknpmg
Chrome Toolbox (by Google) https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn
Awesome Screenshot: Capture & Annotate https://chrome.google.com/webstore/detail/alelhddbbhepgpmgidjdcjakblofbmce
Download Asisstant (by Google) - got killed I guess.