What are the new apps for Office?
Hi, this is Crystal.
I am going to show you what apps for Office are and
how you can get started using them.
A good place to go is Dev.Office.com and start exploring.
I found this free JavaScript "API tutorial for Office" by Microsoft in the app store (Link in video description)
Unfortunately, the instructions for installing this app are not complete.
I'll show you the steps that are missing.
To get the app, click on the "Add" button (it is FREE).
If you are not signed in, fill your Microsoft login credentials and
click "Sign in".
This takes you to a confirmation page
to get the app, click "Continue".
This downloads the app and now it is now accessible.
Now to find it and figure out how to use it.
The first step is to open an application such as Excel.
I hold down the WINDOWS key on my keyboard and press Q (Windows 8).
This takes me to the Windows Search box and I start typing "Excel"
There is the icon to launch it (Excel). I click.
In Excel, I choose the 'Blank Workbook' template.
I go to the INSERT ribbon and choose "Apps for Office",
then "See All ..."
I choose the "API tutorial for Office" app.
I also see another app I got from the store, "Bing Maps".
As I get more apps from the store,
there will be more choices in my catalog.
After I choose the app I want, I click "Insert".
The app is now "Loading..." ... and is taking a long time. There must be something preventing it from loading.
I'll bet it can't load. This is a new installation of Excel. I have not changed any of the defaults.
Out of the box, Excel can't run programs.
Those of you who write VBA, known to many of you as "macros", are aware there are settings you have to change.
Sure enough, here is an APP ERROR that says, "We can't start this app because it isn't set up properly"
Clicking "Retry" doesn't change anything
Clicking "See Details" opens a browser page
to the app listing in the store,
The "Details: section ...
does not explain how to use the app once it is added.
The FAQ doesn't explain what to do either.
Nor does the Requirements.
Luckily we can guess it is something in the Excel Option Settings.
From the ribbon, choose File, Options
While I am here, I am going to change the Office Theme to Dark Gray.
This, of course, has no effect on permissions for the app. I'll just set it while I am here. This makes the ribbons darker.
Now I'll jump down to the Trust Center and click the "Trust Center Settings ..." command button on the right.
There is something I always do the first time I set defaults for a new installation and that is to trust all the drives and subdirectories on these drives that are mounted in my machine.
And that is because I am a programmer
and I put code just about everywhere.
On the left, I choose "Trusted Locations" and
then the "Add new location..." command button.
My first drive is "C:\" and I also check the box so that
all the subforlders on that drive are trusted.
I add my other drives.
When I have a stick plugged in, I will add that drive too.
I also check the box to "Allow Trusted Locations on my network".
Ideally, I'd stop here to see if this is causing the error
with the app not running.
However, I think I see what needs to be set.
There is a new choice called "Trusted App Catalogs".
No doubt I'll be getting more apps from Microsoft in the future; I might as well just trust their whole catalog.
There is a place for a Catalog URL
(URL = Uniform Resource Locator = Web Address)
Where a "Browse..." button would be, I see "Add Catalog"
If I click on the Add Catalog button,
I see an error message because I didn't enter anything to add.
Hey, a cool app would be to browse to a website and then
grab the URL for pasting ... another day, another lesson
-- or maybe one of you will write it.
What would be the Catalog URL?
If I click "Microsoft Corporation" from the store page,
here is what pops up
This is the Store Provider page for Microsoft.
I click in the Address bar of my browser and copy the URL.
In the Excel Settings, I paste the copied URL, and click "Add Catalog"
I get an error again.
The message tells me that httpS:// is required instead of http://
I edit the URL to add an "s" after 'http' and before '://'
By the way, 's' just adds a security option in.
Okay, now click "Add Catalog"
There it is.
I click OK and OK
There is my app with the Retry button so I click it.
Do you think it will work?
Yes, it works.
What is this?
I see a title bar that says,
"Introducing the new JavaScript API for Office".
This first example shows the (JavaScript) code
to write information into a cell ...
... into a SELECTED cell.
I click on cell A1 to select it and
make that the cell where the information will go.
Then I click the "Run Code" button
"Hello World!" now appears in my selected cell.
So what code needs to be written to make this happen?
There isn't much here but it sure does look pretty scary.
Lets break it down
'Office' represents the JavaScript API
Context: According to Help in the Office Dev Center, "The Context object provides access to key objects in the JavaScript API for Office".
-- and that sounds pretty confusing if I wouldn't already know what it meant, so let's look within the context.
One of the properties is "document"
To create a reference to the document that the app is being used in, which in this case is an Excel spreadsheet,
use "Office.context.document", which returns a document object.
One of the methods you can use on a Document object
is "setSelectedDataAsync"
which "Writes data to the current selection in the document."
'Asynch' is short for 'asynchronous.
'A' means 'not' and 'synchronous' means 'with'.
This means that the method can execute immediately
without waiting for something else to get done first as it would be if the method was sequential.
The syntax in the first statement is: Office.context.document.setSelectedDataAsync
(data [, options], callback);
and this means a callback function
The data is "Hello World!"
There are no options specified.
The callback is an ANONYMOUS FUNCTION (thanks, Ben) that uses the AsyncResult from setting the selected data with setSelectedDataAsync. If all went well, no error message will be displayed.
The Status of the asyncResult object is tested to see if writing the data failed so the user can get an an error message.
Whatever data is specified is written to the selected cell.
The Status of the asyncResult object, after this attempt, is tested to see if writing the data failed so the user can get an an error message.
These two code samples do the same thing:
if (asyncResult.status == "failed") is the same as if (asyncResult.status == Office.AsyncResultStatus.Failed)
The other status is "succeeded" or Office.AsyncResultStatus.Succeeded.
Why might an error happen?
By default, in Excel, all cells are Locked -- but that doesn't mean anything until a Worksheet is Protected
So when I Protect the sheet and run this program again,
no matter what cell I am in, I get an error.
I see the literal text specified, "Action failed with error: ",
and then the ambiguous error message, "An internal error has occurred."
which is not very helpful.
Luckily I know the cell is protected. It would have been helpful to include more information in the Error message such as:
"Cannot write. Ensure cell is Unlocked or Worksheet is not Protected. Action failed with error: "
... and then whatever that ambiguous error message would be (+ asyncResult.error.message)
Before a worksheet is protected,
cells to be written to must be unlocked by clearing the Locked box
on the Protection tab of the Format cells dialog box.
The Next Step in the tutorial shows
how to read from the spreadsheet and
uses getSelectedDataAsync instead of setSelectedDataAsync
Get = Read, Set = Write
I click on a blank cell, enter something,
and click the "Run Code" button.
The first parameter for getSelectedDataAsynch is "CoercionType"
Choices are "html", "matrix", "ooxml", "table", and "text"
We want the data back to be a string
so "text" is used for the Coercion Type.
No options are specified.
The callback function returns an error message
if the method failed, as before.
This time, however, the code writes a message
if the method succeeded to literally show
"Selected data: "
and then the value property from the asyncResult object.
To see more tutorials in this app, click the icon in the lower right.
You can choose to see examples to
do more basic operations with Excel.
'Write and Read a Range' uses the "matrix" Coercion Type.
'Write and Read a Table' shows headers and rows
and uses the "table" Coercion Type.
'Update a Row in a Table' shows how to
change the data in one row of a table
'Get Selected Coordinates', which I think is a really lousy name,
shows whatever value is in the ActiveCell
-- so it could have been named better,
uses a "matrix" Coercion Type.
It specifies Options,
and displays the value of the active cell in the message area
as long as the app is open and the
active cell is changed and it is in the matrix that it is looking at
which means each cell in that matrix is going to
TRIGGER the EVENT that writes the message.
'Persist Settings' uses the Office.context.document.settings object to
'set' and 'saveAsync' pairs of setting names and values.
In the upper right of the app is a menu with choices you can explore
Reload starts the app again
View Source shows the HTML in Notepad, or your text editor. It has references to style sheets and JavaScript libraries.
What we are not seeing is the JavaScript to display information in the div areas or process the button clicks.
So View Source doesn't show us code, it shows us Markup.
The difference between Markup and Code is that Markup is static. Code provides the action.
In an Office app, HTML is used to layout what will be displayed. HTML = HyperText Markup Language (for more information, see link in video description)
JavaScript is the programming language.
Show as Saved Image is a toggle to turn whatever is displayed in the app to an image.
You might use this if your app shows a map or chart you want to save or see again.
You can insert more than one copy of the app into your document
You can move the app by dragging its border.
To remove an app from your document, select it and press the DELETE key on your keyboard.
To ask questions about building Office Apps, visit the "Developing Apps for Office 2013" forum in the Office Dev Center
http://social.msdn.microsoft.com/Forums/office/en-US/home?forum=appsforoffice
Link is in the video description, as are all the links that are discussed here.
If I skipped one, let me know and I will add it.
In Summary, I showed you how to download an app
from the Microsoft Store,
how to Insert the app on an Excel spreadsheet,
how to set Excel Options so you have permission to run the app,
and we reviewed code to read and write data.
Thanks for joining me. Through sharing, we will all get better ~ Crystal