Using cookies straight from Excel Get it now

Why would you want to do this? You know what cookies are, and think of them as being a mechanism for web sites to store information about you so they can personalize your experience. As I’ve shown in other sections there are various mechanisms to allow you to pass information between sessions in Excel, and especially if you use an encoding mechanism like JSON, you can make that data very descriptive.

However, in all those cases we are talking about Office Application data interchangeability, and not opening up the connectivity to other things. Let’s say that you wanted to create a web page to be reporting on some activity in an Excel Sheet. Being able to read a cookie that had been maintained by Excel would be very useful. Using a cookie also frees you from having to store the information in a particular sheet. So let’s look at how this is done.

The downloads section on hiding JSON data provides a fully functional example in the workbook trackingdata.xlsm.

Here is the approach I’ve taken
  • Create a temporary web page that has the capability to read and write cookies
  • Navigate to that page to read data from the target cookie, deserialize the JSON data encapsulated in the cookie.
  • Update the cJobject , serialize, create another temporary web page that can write cookies, and update the cookie.
How it’s done
The example we are using is a tracking mechanism that gets updated each time an Excel file is opened or closed

openingdata() was covered in another section and is simply the setup of the data at the beginning of the tracking session, and .Serialize is a method of the cJobject class. Lets look at that cCookie class in more detail. Essentially, both getCookie () and putCookie() use createCookieJar() to generate some javascript which will be executed through doCookie(). This will cause the value of the cookie to be placed in the DIV element, so it can be read as an element of the navigated to document.

Finally, let’s look at the cBrowser class which is invoked by the doCookie method of the cCookie class. This is a general purpose browser handling class.