def set_array_range(worksheet, itop_row, ileft_col, data):
    """insert a 1d or 2d array starting at given location in provided worksheet.

    Args:
        worksheet: win32 Excel object
        itop_row: top row index (zero based)
        ileft_col: left column index (zero based)
        data: numpy array

    Returns:
        win32 Excel Range object
    """
    if len(data.shape) == 1:
        data = data.reshape(data.shape[0], 1)
    ibottom_row = itop_row + data.shape[0] - 1
    iright_col = ileft_col + data.shape[1] - 1
    xlrange = worksheet.Range(worksheet.Cells(itop_row + 1, ileft_col + 1),
        worksheet.Cells(ibottom_row + 1, iright_col + 1))
    xlrange.Value = data.tolist()
    return xlrange
