In Excel Online, OfficeJS API is not passing the host_Info_ parameter anymore to Excel Add-In - excel

I don't know when this started happening or if things have changed but the _host_Info param is not being passed by the framework to my Excel Add-In in Excel Online.
It passes an empty "et=" parameter which is OK in this case since I'm in dev mode. The Excel desktop client is still passing it.
This is required by my add-ins to switch functionality between Excel Online and Excel for Windows.
I've checked the docs and can't find that anything has changed.

To append to Sudhi's answer: with the official API coming as per the link in Sudhi's answer, we've gone ahead and also added a "shim" for the API in the OfficeJsHelpers library.
The shim still uses the workaround code that Sudhi mentions -- window.sessionStorage['hostInfoValue'] -- but it wraps it in an API very similar to what is coming in the official Office.js. Once the official API is available, we'll switch the shim code to make use of that instead. The beauty of this approach is that if you use OfficeJsHelpers via an NPM package, all you have to do is update your package dependency, and you'll suddenly go from an unofficial and potentially-fragile workaround to an API that relies on 100% officially-exposed properties -- all without changing your own code! Likewise, if at that time you decide to switch back to using the official Office.js version, the similarity of the APIs (essentially just namespace differences) should make it trivial to switch over the implementations.
The helper APIs are OfficeHelpers.Utilities.host (which will return WORD, EXCEL, etc.) and OfficeHelpers.Utilities.platform (which will return IOS, PC, OFFICE_ONLINE, or MAC). The constants are defined in OfficeHelpers.HostType and OfficeHelpers.PlatformType.
You can find the NPM package at https://www.npmjs.com/package/#microsoft/office-js-helpers, and either install it via NPM, or use a CDN like Unpkg to quickly try it out: https://unpkg.com/#microsoft/office-js-helpers#0.4.2/dist/office.helpers.min.js
console.log(OfficeHelpers.Utilities.host);
console.log(OfficeHelpers.Utilities.platform);
if (OfficeHelpers.Utilities.platform === OfficeHelpers.PlatformType.OFFICE_ONLINE) {
console.log("Yep, I'm on the web client");
}
I hope you find the above helpful as an interim measure, and we'll be sure to update this StackOverflow thread (and the OfficeJsHelpers code) once the official API is released.

Jim and others who may be affected by this change: it is unfortunate that an unrelated change meant to improve the add-in experience caused the query string parameter in online platform to be removed. Note that URL query parameters and session storage settings are used to launch and setup the add-in environment and are not meant for developer consumption. However, we understand the importance of this to the developers as described in this thread.
Hence, we are adding formal APIs to make this information available. Please see the specs that describes upcoming APIs: https://github.com/OfficeDev/office-js-docs/tree/ContextAdditions_OpenSpec
Until the APIs become available (should be very soon), you could use the following temporary workaround. The same query host_info_ parameter value is available in the following variable: window.sessionStorage.hostInfoValue. Please note that this should be considered a temporary measure and you should switch to using the formal API as soon as they are made available. I'll update the this thread when the API is released, which should be available for all supported Office versions.
If you have any comments, please leave your comments on the specs directly in Github specification branch using the links provided.

UPDATE:
Please see my answer above, instead (https://stackoverflow.com/a/40963500/678505), as the scenario is now possible.
[Old response:]
Jim, could you describe your scenario more? Why is it that you need to distinguish between Online and Desktop?
For the disappearance of host_info_: you won't find it in the docs, because host_info_ was never in the docs. Anything not documented is an internal API, which might change as needed by the internal workings of Office.js. We take back-compat very seriously, but only for actual official documented APIs.
Without an API, there's not much you can do to tell the two apart (or rather, not without relying on other bits of internal workings which might also change over time). We've discussed this internally before, but found it surprisingly difficult to point to a particular scenario where the platform information was necessary and legitimate ("legitimate" in the sense that if you're using platform information to check whether an API is available, for example, that's precisely what we don't want you to do; we want you to use Office.context.requirements.isSetSupported instead).
If you can share your scenario details, I might be able to advise an alternate way of determining whatever you need, or have a solid scenario to bring back to the team.

Related

What is the state of generating Word documents in 2021? (Language agnostic)

Okay, so this is a pretty generic and vague question, so please let me elaborate.
We have a large codebase which we are splitting up the past years to more individual self-contained libraries.
One of the larger and more unwieldy parts is our Word export module. It uses docx4j currently, however we run into memory issues with large exports with a lot of pictures. Besides that, it is pretty difficult to update the exporter due to changes in our domain model.
It has been a while since someone worked on it (like years...) so I took it upon myself to investigate the state of generating Word documents in 2021. I hoped a lot had changed, but some Google searches let me to posts of 2010, and libraries of 2012. Of course, it can be the case that a library of 2012 means it is just that good.
I have identified the following solutions, though I am probably missing a lot:
Docx4j (JVM), still maintained, we run into memory problems with that.
Docx4j with Content Control Data Binding. Seems to be some way to use templating?
Apache POI (JVM), have some okay experience with the Excel part, no experience with the Word part. The 'consensus' online appears to be that Docx4j is more user-friendly.
JasperReports. Don't know anything about that.
DocX, .NET library, no experience.
Office Add-In using Office.js (JS). Official API from Microsoft. Runs at client in Word, so required connection to an API.
docxtemplates (Node / Browser). No experience. Looks complete, don't know about performance though.
officegen (Node). Last release 2019.
Carbone (node). https://github.com/Ideolys/carbone. No experience also.
probably more...
So, as expected a lot of libraries in JS popping up as well.
Looking at my requirements:
using a template would be nice
running it as a service would be nice
efficient (memory wise, don't mind if it takes some time to generate)
We have quite a good JSON API available, which is very easy to maintain and maps pretty good to our domain model. My preference would be to use that as a source of course.
what are peoples experiences and/or am I missing some very good libraries out there?

Creating a github dashboard on portfolio site

Thank you for giving me a piece of your time. This question really isn't a "how to", but more of a "is this possible or am I just insane?". I've recently looked at some portfolio pages and found a really great idea from https://flexdinesh.github.io/, but in the "portfolio" section instead of having just the characteristics of the project, is it possible to somehow use the Github API or some other equivalent to extract and present data like number of commits (or the table that github shows on your project page) and what project type it is (i.e. Java, Javascript, etc.) and maybe even some more related information. For background I am using React with Node.js. Again, this is probably useless to everyone out there, but I think it could be something cool if A) it actually exists, and B) it's not too much of a pain to implement. I've tried reading up on the documentation from Github, looking online, and looking at different source code, but no luck there. If anyone has any information or feedback I'm always open to help!
Thank you and have a good day
from what I understand, you want to display statistical information about the projects on your portfolio website.
Github provides an API that can get almost all the information you see on their website
so, to get all the languages being used in repository you can do a GET request on https://api.github.com/repos/:owner/:repo/languages,
To get the number of commits you can do a GET request on https://api.github.com/repos/:owner/:repo/commits
and so on
By default, these will get you the data of the public repositories, if you want to display info from your Private repositories, you need to provide an authentication token with each request.
You can read more about the API calls available here
let me know if you need any more help

Word Addin - how to check if the createDocument() function is available?

I am using Office JS to develop a Word addin.
Thanks to previous answers, I found that I can open a new document in Word by doing:
context.application.createDocument().open();
However, that seems to only work on the Desktop version of Office.
If I try that same addin in the online version, I get an error:
Sorry, this function isn’t available. Perform a runtime check on the Office add-in to find out whether the feature is supported by the host
How can I programatically find out if that function is available so that I can make the plugin default to a different behavior if it's not?
Also, is there some documentation on the createDocument function? (I googled and could not find anything).
In the general case, you should use the isSetSupported API check at runtime to be able to see whether a particular method is available. See https://dev.office.com/docs/add-ins/develop/office-js-versioning
In this particular case, you're running into the fact that createDocument is part of a not-yet-released (preview-only) WordApi 1.4 (PREVIEW) API set (you can see it in the IntelliSense, both in the d.ts file (TypeScript) and vsdoc (JavaScript in VS 2015 and earlier). For example, in https://github.com/OfficeDev/office-js/blob/beta/dist/office.d.ts
Because it's Preview, this unfortunately means that isSetSupported will return "false" regardless... because it simply might not be reliably available anywhere yet (or at least, the team has not signed off on it being done and available). So for these Preview APIs, it's really meant just for your own dev testing, not anything you would use in production.

Liferay upgrade from 6.0.6CE to 6.2CE

I am planning to upgrade my company's intranet from liferay 6.0.6CE to 6.2CE. I have done some research on it but I am still confused on API part. Will my custom portlets need only recompilation or would they need a complete rewriting. I am also concerned about my Theme and Exts. I have a lot of customization in my exts and my theme. What would be the best way to move ahead?
Also I have a NFS file server and SOLR search server configured with my current deployment. Need suggestions on that too.
I've heard recently, that the Migration Tool (6.1 to 6.2) now also supports themes. It won't be pixel perfect though. Check what it can do for you.
There have been some APIs that changed. Contrary to the comments given to your question, I'd say "It depends": I don't know how much of Liferay's API you use or if you just add functionality on top. You'll have to find out for yourself. The migration tool might help you.
The things that have changed the most are: Themes (using Bootstrap, as of 6.2) and Document Library (now including ImageGallery, which was still available in 6.0). Migration of data should be smooth if you follow the documented upgrade path. Migration of your portlets and plugins will definitely require recompile (within the new plugins sdk or updated maven dependencies) and probably adaptation to some changed API calls. I've seen instances where this was simple, but I've also seen hard cases.
As there have been no more updates for 6.0 CE for quite a while, I'm recommending to upgrade though (other than #FeinesFabi in the comment). If you want to have a long-term stable platform that you don't need to maintain for yourself, EE would be the way to go (supported for ~7 years after release)
For ext changes, you'll have to be aware that there are no guarantees: Ext allows you to change the inner implementation of Liferay, and that's what nobody strives to keep stable, even in minor updates. If you're using ext, you'll always have to be aware of incompatible changes. Ext allows you to keep your changes out of the official sourcecode - so they're well isolated. It doesn't say anything about the underlying implementation to be stable. With great power (ext) comes great responsibility. Keep your ext as small as possible - whatever you can do outside of ext should be done outside and use the public API.
The basic upgrade path (for Liferay itself, not your plugins) is quite well documented in the User's Guide.

SharePoint - Posting and Retrieving files Automatically via VBScript

I'm going to need to push and pull files from a SharePoint site that is not hosted by my company (it is external). I'm only going to get a few days (if that) to get this working so I don't have much time to experiment.
To add to my requirements/headaches, I'm going to have to implement this with VBScript. .Net would be preferred for me but for reasons beyond my control I have to use VBScript. I don't have direct access to my VBScript web server, so I won't be able to implement this in .NET and use that object from VBScript.
I'm looking for anything that would help me accomplish this goal quickly and effectively. I found this post and am wondering if the PUT/GET method used here would work for me?
http://weblogs.asp.net/bsimser/archive/2004/06/06/149673.aspx (I got this link from: Sharepoint API - How to Upload files to Sharepoint Doc Library from ASP.NET Web Application)
To top all of this off, I've never done any programming or administration of a SharePoint site. My knowledge of SharePoint is that of a user. I'm aware that there is an API from the few Google searches I did. However, my readings make me believe that my code would need to run on or in proximity to the SharePoint server. I don't believe I have the proximity I need to use the API.
Sincere thank yous!
Regards,
Frank
Progress Update: I'm still researching this. Tom pointed out that the example I had posted is probably from an old SharePoint version. His recommendation to use .Net to develop a prototype on Web Services is good but I'm hoping for more detailed answers.
I'm now wondering if I can accomplish what I need to accomplish using HTTP PUT and GETs. At my company, for a specific project we do use HTTP PUT and GETs to do something like this. We have files that are stored on an HTTP server and this is how we post and retrieve them.
Would this work over SharePoint or would SharePoint require special handling? Basically, do I have to use Web Services?
Progress Update 2: This link is helpful... Upload a file to SharePoint through the built-in web services
But I am still looking for more information on this topic... Thanks all...
You'll need to use the sharepoint lists web service for metadata and get/put for uploads. That link looks to be for SharePoint 2001, so hopefully you can use the newer/simpler version.
I recommend building something in .net first to get the web service calls worked out - some of the parameters can be quite tricky to debug, and I wouldn't want to be doing that on a remote vbscript page.
Assuming there is no metadata required and the SharePoint library is being used like a file server you can do most of what you want with PUT/GET, but you will probably need a call to GetListItems to find the urls to download.
There's an example on my blog of a lower level call to that web service - it's javascript, but probably close enough.
http://tqcblog.com/2007/09/24/sharepoint-blog-content-rating-with-javascript-and-web-services
What setting up the .net version gets you is very quick set up of a connection to the server (just add a web service reference in visual studio) so you can get the query and queryoptions strings working to retrieve the items you want. Once that works you just have to put it all together as a string including the soap stuff for use without all the nice tools.
I'm a little unclear on the context of the implementation and the prerequisite of having to use VBScript. Are the files being moved from one server to another server or from a user's desktop to this SP server? or are they being accessed via software like Excel?
The first thing that sprang to my mind (this may sound crazy) was using the Office application to make the connection. Your script would call up Excel (just as an example) and pass it the vba needed to initiate the Open File, and then provide the full path to the file that needs to be retrieved. Then have it do a Save As to the location that needs the file. Do the same thing but in reverse for putting files on the SharePoint server.
The tricky part, obviously, is getting the script to interface with the Office app. I know this can be done with the Windows version of PHP, but I don't want to get into anything specific without knowing your situation.
I seriously wonder if you are going to be able to use VBScript to call the SharePoint web services. I haven't looked at the SharePoint web services for a while so I don't remember exactly how they are defined. I thought the web services were SOAP calls though which makes it trickier than
I'm not sure I tried to use Excel to call some web services with the MSSOAP.SoapClient and it seemed this component was unable to handle any WSDL types beyond the very simple strings. Anything with nested data would not work. Instead, you would need to create a COM object to process the conversion which is a major hassle. If you are able to use XMLHTTP component then it might be possible with VBScript, but I'm not sure if it will work with SharePoint web services.
I'm not sure what you mean, "I don't have direct access to my VBScript web server." Is your web server in VBScript (ASP)? Or did you mean SharePoint server?
You might consider C# Script (cs-script) as a scripted solution that uses .NET. I have had good success with it, although it does need to be installed on the computer that runs the script.
I'm integrating between two companies. According to this book, we should use AD FS to accomplish what I'm looking for.
I still don't actually have this working though so if someone has more information I will change the answer to this question.
http://books.google.com/books?id=-6Dw74If4N0C&pg=PA27&lpg=PA27&dq=sharing+sharepoint+sites+external+adfs&source=bl&ots=ojOlMP13tE&sig=FjsMmOHymCOMGo7il7vjWF_lagQ&hl=en&ei=ytqfStClO5mMtgejsfH0Dw&sa=X&oi=book_result&ct=result&resnum=5#v=onepage&q=&f=false
I never really received a answer to this that worked out but this is no longer an issue for me.
What we ended up doing is scraping the html. In effect, we put together our own ad-hoc web service processor where instead of SOAP, html is used to communicate. Then we execute GETs, POSTs, and etc to work with the web service.
We had done something similar in VBScript in for WebDAV -- we had a class and created a new one to work with SharePoint.

Resources