# GC.Spread.Sheets.Collaboration.Collaboration

## Content

# Class: Collaboration

[Sheets](../modules/GC.Spread.Sheets).[Collaboration](../modules/GC.Spread.Sheets.Collaboration).Collaboration

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.Collaboration.Collaboration#constructor)

### Methods

- [applyChangeSet](GC.Spread.Sheets.Collaboration.Collaboration#applychangeset)
- [endBatchOp](GC.Spread.Sheets.Collaboration.Collaboration#endbatchop)
- [fromSnapshot](GC.Spread.Sheets.Collaboration.Collaboration#fromsnapshot)
- [getPresences](GC.Spread.Sheets.Collaboration.Collaboration#getpresences)
- [getUser](GC.Spread.Sheets.Collaboration.Collaboration#getuser)
- [onChangeSet](GC.Spread.Sheets.Collaboration.Collaboration#onchangeset)
- [registerCollaborationType](GC.Spread.Sheets.Collaboration.Collaboration#registercollaborationtype)
- [setPresences](GC.Spread.Sheets.Collaboration.Collaboration#setpresences)
- [setUser](GC.Spread.Sheets.Collaboration.Collaboration#setuser)
- [startBatchOp](GC.Spread.Sheets.Collaboration.Collaboration#startbatchop)
- [toSnapshot](GC.Spread.Sheets.Collaboration.Collaboration#tosnapshot)

## Constructors

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

• **new Collaboration**(`workbook`)

Represents a collaboration manager that can manage collaboration status.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `workbook` | [`Workbook`](GC.Spread.Sheets.Workbook) | The workbook. |

## Methods

### <a id="applychangeset" name="applychangeset"></a> applyChangeSet

▸ **applyChangeSet**(`changeSet`): `void`

Only used in collaboration case, to apply doc's op.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `changeSet` | [`IChangeSet`](../interfaces/GC.Spread.Sheets.Collaboration.IChangeSet) | change set |

#### Returns

`void`

___

### <a id="endbatchop" name="endbatchop"></a> endBatchOp

▸ **endBatchOp**(): `void`

Ends the current batch operation, finalizing the collection of operations into a single ChangeSet.
This method must be called after `startBatchOp` to complete the batch process.

**`example`**
```javascript
spread.collaboration.startBatchOp();
sheet.setValue(0, 1, "World");
sheet.setFormula(0, 2, "=SUM(A1:B1)");
spread.collaboration.endBatchOp(); // The value and formula changes are merged into one ChangeSet.
```

#### Returns

`void`

___

### <a id="fromsnapshot" name="fromsnapshot"></a> fromSnapshot

▸ **fromSnapshot**(`snapshot`): `void`

Only used in collaboration case, to restore the snapshot to workbook state.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `snapshot` | `Object` | snapshot object |

#### Returns

`void`

___

### <a id="getpresences" name="getpresences"></a> getPresences

▸ **getPresences**(): [`IPresence`](../modules/GC.Spread.Sheets.Collaboration#ipresence)[]

Get presences for workbook

**`example`**
```javascript
// This example gets presences.
const presences = spread.collaboration.getPresences();
```

#### Returns

[`IPresence`](../modules/GC.Spread.Sheets.Collaboration#ipresence)[]

presences - The presences info.

___

### <a id="getuser" name="getuser"></a> getUser

▸ **getUser**(): [`IUser`](../modules/GC.Spread.Sheets.Collaboration#iuser)

Get user for workbook

**`example`**
```javascript
// this example gets the current user.
const user = spread.collaboration.getUser();
```

#### Returns

[`IUser`](../modules/GC.Spread.Sheets.Collaboration#iuser)

___

### <a id="onchangeset" name="onchangeset"></a> onChangeSet

▸ **onChangeSet**(`onOpHandler`): `void`

Only used in collaboration case, to watch change set.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `onOpHandler` | [`IChangeSetHandler`](../modules/GC.Spread.Sheets.Collaboration#ichangesethandler) | callback to watch change set |

#### Returns

`void`

___

### <a id="registercollaborationtype" name="registercollaborationtype"></a> registerCollaborationType

▸ **registerCollaborationType**(`type`): `void`

Only used in collaboration case, to register collaboration type.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `type` | [`IOT_Type`](../interfaces/GC.Spread.Sheets.Collaboration.IOT_Type) | collaboration type |

#### Returns

`void`

___

### <a id="setpresences" name="setpresences"></a> setPresences

▸ **setPresences**(`presences`): `void`

Set the presences info.

**`example`**
```javascript
//This example updates the current presences.
let presences = [{
    user: {
        id: '1',
        name: 'User1',
        color: '#FF0000',
        permission: {
            mode: GC.Spread.Sheets.Collaboration.BrowsingMode.edit,
        }
    },
    status: {
        selections: {
             selections: [new GC.Spread.Sheets.Range(0, 0, 1, 1)],
             sheetId: 'sheet1'
        }
    }
}, {
    user: {
        id: '2',
        name: 'User2',
        permission: {
            mode: GC.Spread.Sheets.Collaboration.BrowsingMode.edit,
        }
    },
    status: {
        selections: {
             selections: [new GC.Spread.Sheets.Range(2, 2, 3, 5)],
             sheetId: 'sheet1'
        }
    }
}]
spread.collaboration.setPresences(presences);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `presences` | [`IPresence`](../modules/GC.Spread.Sheets.Collaboration#ipresence)[] | The presences info. |

#### Returns

`void`

___

### <a id="setuser" name="setuser"></a> setUser

▸ **setUser**(`user`): `void`

Sets the current user.

**`example`**
```javascript
//This example sets the current user.
let user = {
    id: '1',
    name: 'User1',
    color: '#FF0000',
    permission: {
        mode: GC.Spread.Sheets.Collaboration.BrowsingMode.edit,
    }
}
spread.collaboration.setUser(user);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `user` | [`IUser`](../modules/GC.Spread.Sheets.Collaboration#iuser) | The current user. |

#### Returns

`void`

___

### <a id="startbatchop" name="startbatchop"></a> startBatchOp

▸ **startBatchOp**(): `void`

Starts a batch operation, allowing multiple operations to be grouped and merged into a single ChangeSet.
When called, all operations performed until `endBatchOp` is invoked are collected and treated as a single atomic change in the SpreadJS workbook.

**`example`**
```javascript
spread.collaboration.startBatchOp();
sheet.setValue(0, 0, "Hello");
sheet.setFormula(0, 2, "=SUM(A1:B1)");
spread.collaboration.endBatchOp(); // All operations above are merged into a single ChangeSet.
```

#### Returns

`void`

___

### <a id="tosnapshot" name="tosnapshot"></a> toSnapshot

▸ **toSnapshot**(): `Object`

Only used in collaboration case, to save workbook state to snapshot.

#### Returns

`Object`

snapshot - snapshot object
