Excel Rich API Demo

What is Excel Rich API?

Excel Rich API is a new version of JavaScript API that can be used in Excel Add-ins to manipulate the spreadsheets. The interface of the APIs is consistent across the different platforms. Details can be found at Microsoft MSDN.

How to Play with the Excel Rich API?

The Excel Rich API Demo app helps you to learn and play with the new set of Excel Rich APIs. You can open a spreadsheet from Excel or Excel Online, and insert this demo app as a Taskpane Add-in. You can do this by click the Insert menu item, then click the My Add-ins icon in the ribbon bar, and choose this app from Office STORE and insert it into your document, and the add-in will be displayed together with your spreadsheet.

In the upper Code text box, enter your code or copy/paste from the Microsoft MSDN, and then click Execute. If you want to show the output in the lower Output box, please call writeLog() method to show the logs or results. If you are running the add-in in Excel Online, then you can also call console.log() to output to the browser debug console. You need to open the console to see the output.

Excel Rich API Sample Code

Below are the samples that use the Excel Rich APIs. These samples can help you to get familiar with the syntax and styles of these Excel APIs. You can copy the sample code and paste it into the code text box in the demo app, and click Execute to run it.

Sample Code: RangeBorder Property


 Excel.run(function (ctx) { 
 	var sheetName = "Sheet1";
 	var rangeAddress = "A1:F8";
 	var range = ctx.workbook.worksheets.getItem(sheetName).getRange(rangeAddress);
	range.format.borders.getItem('InsideHorizontal').style = 'Continuous';
 	range.format.borders.getItem('InsideVertical').style = 'Continuous';
	range.format.borders.getItem('EdgeBottom').style = 'Continuous';
 	range.format.borders.getItem('EdgeLeft').style = 'Continuous';
 	range.format.borders.getItem('EdgeRight').style = 'Continuous';
 	range.format.borders.getItem('EdgeTop').style = 'Continuous';
 	return ctx.sync(); 
}).catch(function(error) {
 	console.log("Error: " + error);
 	if (error instanceof OfficeExtension.Error) {
 		console.log("Debug info: " + JSON.stringify(error.debugInfo));
 	}
});