method
each
v2_2_9 -
Show latest stable
- Class:
WIN32OLE
each()public
Iterates over each item of OLE collection which has IEnumVARIANT interface.
excel = WIN32OLE.new('Excel.Application') book = excel.workbooks.add sheets = book.worksheets(1) cells = sheets.cells("A1:A5") cells.each do |cell| cell.value = 10 end
static VALUE
fole_each(VALUE self)
{
LCID lcid = cWIN32OLE_lcid;
struct oledata *pole = NULL;
unsigned int argErr;
EXCEPINFO excepinfo;
DISPPARAMS dispParams;
VARIANT result;
HRESULT hr;
IEnumVARIANT *pEnum = NULL;
void *p;
RETURN_ENUMERATOR(self, 0, 0);
VariantInit(&result);
dispParams.rgvarg = NULL;
dispParams.rgdispidNamedArgs = NULL;
dispParams.cNamedArgs = 0;
dispParams.cArgs = 0;
memset(&excepinfo, 0, sizeof(excepinfo));
pole = oledata_get_struct(self);
hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DISPID_NEWENUM,
&IID_NULL, lcid,
DISPATCH_METHOD | DISPATCH_PROPERTYGET,
&dispParams, &result,
&excepinfo, &argErr);
if (FAILED(hr)) {
VariantClear(&result);
ole_raise(hr, eWIN32OLERuntimeError, "failed to get IEnum Interface");
}
if (V_VT(&result) == VT_UNKNOWN) {
hr = V_UNKNOWN(&result)->lpVtbl->QueryInterface(V_UNKNOWN(&result),
&IID_IEnumVARIANT,
&p);
pEnum = p;
} else if (V_VT(&result) == VT_DISPATCH) {
hr = V_DISPATCH(&result)->lpVtbl->QueryInterface(V_DISPATCH(&result),
&IID_IEnumVARIANT,
&p);
pEnum = p;
}
if (FAILED(hr) || !pEnum) {
VariantClear(&result);
ole_raise(hr, rb_eRuntimeError, "failed to get IEnum Interface");
}
VariantClear(&result);
rb_ensure(ole_each_sub, (VALUE)pEnum, ole_ienum_free, (VALUE)pEnum);
return Qnil;
} Related methods
- Instance methods
- []
- []=
- _getproperty
- _invoke
- _setproperty
- each
- invoke
- method_missing
- ole_activex_initialize
- ole_free
- ole_func_methods
- ole_get_methods
- ole_method
- ole_method_help
- ole_methods
- ole_obj_help
- ole_put_methods
- ole_query_interface
- ole_respond_to?
- ole_type
- ole_typelib
- setproperty
- Class methods
- codepage
- codepage=
- connect
- const_load
- create_guid
- locale
- locale=
- new
- ole_free
- ole_initialize
- ole_reference_count
- ole_show_help
- ole_uninitialize