Microsoft Office Tutorials and References
In Depth Information
Web Service API Methods
The sample creates a program that monitors the addition of workbooks in a target file location (provided
by the second argument). Excel Services opens workbooks that get added to the target location, force a
calculation of the workbook, and then save the calculated workbook to an output file location (provided
by the first argument). As far as the usage of Excel Services API is concerned, this is a straightforward
example. The program calls on the OpenWorkBook method, the CalculateWorkbook method, and the
GetWorkbook method to complete the steps described previously.
Here is the sample code:
namespace ExcelServicesCalcDemo
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using ExcelServices;
class Program
// The destination directory holds the location
// to which the calculated workbooks will be saved
private static string DestinationDirectory;
static void Main(string[] args)
DestinationDirectory = args[0];
// Listen for any new *.xlsb files created in a given folder.
// Call the OnFileCreated method for every such file
FileSystemWatcher fileWatcher = new FileSystemWatcher(
fileWatcher.Created += new FileSystemEventHandler(OnFileCreated);
fileWatcher.EnableRaisingEvents = true;
private static void OnFileCreated(object source, FileSystemEventArgs e)
// Create the Excel Service web service caller
ExcelService service = new ExcelService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Open the workbook, calculate it, get the workbook
// into a byte array and close the session
Status[] status;
string sessionId = service.OpenWorkbook(
Search JabSto ::

Custom Search