win32ole ---> Excel





  


win32ole is a helper class for windows OLE, which is used to control other programs such as excel, outlook etc. The libraries turn Ruby into a powerful and convenient Windows scripting language. Now you have the power to control your applications, but in a controlled, object-oriented environment.

ole "Object Linking and Embedding is a proprietary technology developed by Microsoft that allows embedding and linking to documents and other objects. On a technical level, an OLE object is any object that implements the IOleObject interface, possibly along with a wide range of other interfaces, depending on the object's needs"

win32ole in Automation
By using WIN32OLE, you can access OLE server like VBScript. Some of the major components of an automation framework are applications like Excel. In this article I will touch upon few ways win32ole can help you when working with beautiful Ruby, viz.

Pre-requisite:
require 'win32ole'

1) Excel:
excel = WIN32OLE.new('Excel.Application')
excel.visible = true
workbook = excel.Workbooks.Add();
worksheet = workbook.Worksheets(1);
worksheet.Range("A1:D1").value = ["ALEX","JOHN","TESS","WAYNE"];
worksheet.Range("A2:B2").value = [5.2, 10];
worksheet.Range("C2").value = 8;
worksheet.Range("D2").value = 20;

range = worksheet.Range("A1:D2");
range.select
chart = workbook.Charts.Add;

workbook.saved = true;

excel.ActiveWorkbook.Close(0);
excel.Quit();
 
Here, workbook.saved = true #Setting it to True is a simple way of preventing the "Do you wish to save..." dialog appearing when Excel is closed.

Application of the concept:
With respect to automation the concept has huge application in designing data-driven framework wherein one would need to pull and save data in an excel file . Ruby offers beautiful methods to make this interaction seamless and easy.
 

Comments

Popular Posts