# GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection

## Content

# Class: FloatingObjectCollection

[Sheets](../modules/GC.Spread.Sheets).[FloatingObjects](../modules/GC.Spread.Sheets.FloatingObjects).FloatingObjectCollection

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#constructor)

### Methods

- [add](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#add)
- [all](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#all)
- [clear](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#clear)
- [get](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#get)
- [remove](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#remove)
- [zIndex](GC.Spread.Sheets.FloatingObjects.FloatingObjectCollection#zindex)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new FloatingObjectCollection**(`sheet?`, `typeName?`)

Represents a floating object manager that managers all floating objects in a sheet.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `sheet?` | [`Worksheet`](GC.Spread.Sheets.Worksheet) | The worksheet. |
| `typeName?` | `string` | The type name. |

## Methods

### <a id="add" name="add"></a> add

▸ **add**(`floatingObjectOrName`, `src?`, `x?`, `y?`, `width?`, `height?`): [`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)

Adds a floating object to the sheet.
The arguments has 2 modes.
If there is 1 parameter, the parameter is floatingObject which is a GC.Spread.Sheets.FloatingObjects.FloatingObject type.
If there are 6 parameters, the parameters are name, src, x, y, width, and height.

**`example`**
```
var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("f1", 10, 10, 60, 64);
var btn = document.createElement('button');
btn.style.width = "60px";
btn.style.height = "30px";
btn.innerText = "button";
customFloatingObject.content(btn);
activeSheet.floatingObjects.add(customFloatingObject);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `floatingObjectOrName` | `string` \| [`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject) | The floating object that will be added to the sheet, or the name of the picture that will be added to the sheet. |
| `src?` | `string` | The image source of the picture. |
| `x?` | `number` | The x location of the picture. |
| `y?` | `number` | The y location of the picture. |
| `width?` | `number` | The width of the picture. |
| `height?` | `number` | The height of the picture. |

#### Returns

[`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)

The floating object that has been added to the sheet.

___

### <a id="all" name="all"></a> all

▸ **all**(): [`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)[]

Gets all of the floating objects in the sheet.

**`example`**
```
activeSheet.pictures.add("p1", "pics/download.jpg", 1, 6, 400, 400);
activeSheet.pictures.add("p2", "pics/download.jpg", 500, 150, 200, 300);
var pictures = activeSheet.pictures.all();
for (var i = 0; i &lt; pictures.length; i++) {
    alert("Path of picture " + i + " is:  " + pictures[i].src())
}
```

#### Returns

[`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)[]

The collection of all the floating objects in the sheet.

___

### <a id="clear" name="clear"></a> clear

▸ **clear**(): `void`

Removes all floating objects in the sheet.

**`example`**
```
var f1 = new GC.Spread.Sheets.FloatingObjects.FloatingObject('f1', 10, 10, 64, 30);
f1.content(createButton('button 1', '64px', '30px'));
activeSheet.floatingObjects.add(f1);

var f2 = new GC.Spread.Sheets.FloatingObjects.FloatingObject('f2', 100, 10, 64, 30);
f2.content(createButton('button 2', '64px', '30px'));
activeSheet.floatingObjects.add(f2);

console.log(activeSheet.floatingObjects.all().length); // result is 2
activeSheet.floatingObjects.clear(); // removes all floating objects.
console.log(activeSheet.floatingObjects.all().length); // result is 0

function createButton (text, width, height) {
    var btn = document.createElement('button');
    btn.style.width = width;
    btn.style.height = height;
    btn.innerText = text;
    return btn;
}
```

#### Returns

`void`

___

### <a id="get" name="get"></a> get

▸ **get**(`name`): [`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)

Gets a floating object from the sheet by the indicate name.

**`example`**
```
activeSheet.pictures.add("f2","tsoutline.png",100,60,200,100);
//button
$("#button1").click(function () {
 var pic = activeSheet.pictures.get("f2");
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the floating object. |

#### Returns

[`FloatingObject`](GC.Spread.Sheets.FloatingObjects.FloatingObject)

The floating object in the sheet with the indicate name.

___

### <a id="remove" name="remove"></a> remove

▸ **remove**(`name`): `void`

Removes a floating object from the sheet by the indicate name.

**`example`**
```
activeSheet.pictures.add("f2","tsoutline.png",100,60,200,100);
//button
$("#button1").click(function () {
     activeSheet.resumePaint();
     activeSheet.pictures.remove("f2");
     activeSheet.repaint();
});
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the floating object. |

#### Returns

`void`

___

### <a id="zindex" name="zindex"></a> zIndex

▸ **zIndex**(`name`, `zIndex?`): `any`

Gets or sets the z-index of floating object.

**`example`**
```
var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("f1", 20, 20, 60, 64);
var btn = document.createElement('button');
btn.style.width = "60px";
btn.style.height = "30px";
btn.innerText = "button1";
customFloatingObject.content(btn);
activeSheet.floatingObjects.add(customFloatingObject);
var customFloatingObject1 = new GC.Spread.Sheets.FloatingObjects.FloatingObject("f2", 5, 5, 30, 64);
var btn1 = document.createElement('button');
btn1.style.width = "60px";
btn1.style.height = "30px";
btn1.innerText = "button2";
customFloatingObject1.content(btn1);
activeSheet.floatingObjects.add(customFloatingObject1);
activeSheet.floatingObjects.zIndex("f2", 897);
activeSheet.floatingObjects.zIndex("f1", 898);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name of the floatingObject. |
| `zIndex?` | `number` | The z-index of the floating object. |

#### Returns

`any`

If the parameter 'zIndex' is null or undefined,it will return the z-index of the floating object with the indicate name.
