Protection

Spread allows you to limit user operations in a workbook. By locking/unlocking cells or making menus visible/invisible you can decide what users can edit or not.

Description
app.jsx
app-func.jsx
app-class.jsx
index.html
styles.css
Copy to CodeMine

Sometimes you don't want the values of cells in a sheet to be edited. If so, you can use the isProtected option to set and get whether the sheet is protected.

       var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
       var sheet = spread.getActiveSheet();
       sheet.options.isProtected = true;
       sheet.options.isProtected; // true

If you want to protect the worksheet with a password, you can use protect, unprotect and hasPassword API.

       var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
       var sheet = spread.getActiveSheet();
       var password = '<user_input>';
       sheet.protect(password);
       // ...
       if (sheet.hasPassword()) {
              var passwordUnlock = '<user_input>';
              var success = sheet.unprotect(passwordUnlock);
              // ...
       } else {
              sheet.unprotect(); // or sheet.options.isProtect = false;
       }

When a sheet is protected, you can use protectionOptions to limit user actions by providing an object with the following properties:

allowSelectLockedCells: Boolean that represents whether the user can select locked cells.

allowSelectUnlockedCells: Boolean that represents whether the user can select unlocked cells.

allowSort: Boolean that represents whether the user can sort ranges.

allowFilter: Boolean that represents whether the user can filter ranges.

allowEditObjects: Boolean that represents whether the user can edit floating objects.

allowResizeRows: Boolean that represents whether the user can resize rows.

allowResizeColumns: Boolean that represents whether the user can resize columns.

allowDragInsertRows: Boolean that represents whether the user can drag insert rows.

allowDragInsertColumns: Boolean that represents whether the user can drag insert columns.

allowInsertRows: Boolean that represents whether the user can insert rows.

allowInsertColumns: Boolean that represents whether the user can insert columns.

allowDeleteRows: Boolean that represents whether the user can delete rows.

allowDeleteColumns: Boolean that represents whether the user can delete columns.

allowOutlineRows: Boolean that represents whether the user can expand or collapse row outline.

allowOutlineColumns: Boolean that represents whether the user can expand or collapse column outline.

       var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
       var sheet = spread.getActiveSheet();
       sheet.options.protectionOptions = {
             allowSelectLockedCells: true, 
             allowSelectUnlockedCells: true,
             allowSort: false 
             allowInsertColumns: true 
       };
       var option = sheet.options.protectionOptions;
       console.log(JSON.stringify(option, null, 2));
Sometimes you don't want the values of cells in a sheet to be edited. If so, you can use the isProtected option to set and get whether the sheet is protected. If you want to protect the worksheet with a password, you can use protect, unprotect and hasPassword API. When a sheet is protected, you can use protectionOptions to limit user actions by providing an object with the following properties: allowSelectLockedCells: Boolean that represents whether the user can select locked cells. allowSelectUnlockedCells: Boolean that represents whether the user can select unlocked cells. allowSort: Boolean that represents whether the user can sort ranges. allowFilter: Boolean that represents whether the user can filter ranges. allowEditObjects: Boolean that represents whether the user can edit floating objects. allowResizeRows: Boolean that represents whether the user can resize rows. allowResizeColumns: Boolean that represents whether the user can resize columns. allowDragInsertRows: Boolean that represents whether the user can drag insert rows. allowDragInsertColumns: Boolean that represents whether the user can drag insert columns. allowInsertRows: Boolean that represents whether the user can insert rows. allowInsertColumns: Boolean that represents whether the user can insert columns. allowDeleteRows: Boolean that represents whether the user can delete rows. allowDeleteColumns: Boolean that represents whether the user can delete columns. allowOutlineRows: Boolean that represents whether the user can expand or collapse row outline. allowOutlineColumns: Boolean that represents whether the user can expand or collapse column outline.
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample ReactDOM.render(<AppFunc />, document.getElementById('app')); // 2. Class Component sample // ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; const passwordWrongTip = 'Password is not correct!'; const alreadyProtect = 'The worksheet is already protected!'; const unprotectImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB0UlEQVR4nO2YzU7CQBDHNyae9A30qF6NNlFv7QzhqheukN1An4Mbnv14A70YwgERX0XiWRNBKl8eMDGuGWy0LopoS0tl/8kkZLMT/r+dmW1axrS0tAKTYRjziJgCgFNEvAKAR0Tsub9pLUV72DTKsqw9ALhGRDkqaA/tZdOifD4/h4j7PxlX4gURC5QbtX/2B/PeKERqnlrBPU1vi/QR8dCyrO1kMrlAYZrmDgAcAcCTWgkA2I3EPA2j2vMAcAMA69/lJBKJDQC4VWfCiGKw6UZRT36UeU/e5heVSLGw5V6LXhMHv8g9VuBPWNhCxJoCsDVuLs2EkltjYct9QL2bME1zcdxc2qsA9FjYUq/EsPN9SwOgrsD4yuVyy5zzIue8K4SQkwz+9h8lzvlqkOadSRsXwyBOJpNZ8g1AJx+2efEBcRYEQDdCgLZvgKjMCzc0gNAVELqFfGkmW8i2bXl5cS7bTkO2mnVZrZQHa7EBqFbKUj73PwWtxQag7TSGAGgtNgCtZn0I4OH+Lj4A1bi3kG3bA8NUiVgOsQgwmAYQugJSt9Cst1An7q+UpQgBir4B0un0mhCiGYF5J5vNrrAgRN9n6BNHSO3UoZMPzLyW1j/XK1zJDTLJ864hAAAAAElFTkSuQmCC'; const protectImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB10lEQVR4nO2Yz0rDQBDGB0Ev+gZ6VK+iAfWWzJRe9dL3qfVQlWwR/7yBXqT0JepD2Nar0h4s2ERq3YArW4LGrdZq0qSx+8FACDvw/XZmNmQBtLS0IpNhGLNElEPESyK6QcQnInL9Z/kuJ9fAJMqyrF1EbBCRGBZyjVwLk6J8Pj9DRAc/GVfilYiKMjdp//AH88EoJmpetoK/m8EW6RHRqWVZW9lsdl6GaZrbiHiGiC9qJRBxJxHzchjVnkfEO0Rc+y4nk8msI+K9OhNGEoMtTxR154eZD+RtfFGJHMQt/1gMmjj5Re65An8BcYuIagrA5qi5ciaU3BrELf8D9W7CNM2FUXPlWgXAhbilHolx54eWBiBdgdElDmGJMyhzBo7HQIwzOAOHM6j0jmAlOvM2tMdt3FNBbGiLEiyGBpA7H7d576MaV1EAOAkCPIYGSMq854cG8HQFQLdQKE1nCx3Pie71vnBbDeE266JbLfTfpQagWy0Ix3E+RR8iLQBuqzEA4LZuUwTQrA8CNGtpb6G9lA1xtdCvRCqH2IswQAMwXQGhW2iqW4jb0En1LyVnUEkQoBwaoMdglTN4iN28De3nEixDFJL3M/KKI4524jZ05M5HZl5L65/rDc6nQtkkwmMVAAAAAElFTkSuQmCC'; const useState = React.useState; let spread = null; export function AppFunc() { const [protectSheet, setProtectSheet] = useState(true); const [selectLockedCells, setselectLockedCells] = useState(true); const [selectUnlockedCells, setselectUnlockedCells] = useState(true); const [sort, setSort] = useState(false); const [filter, setfilter] = useState(true); const [resizeRows, setresizeRows] = useState(true); const [resizeColums, setresizeColums] = useState(false); const [editObject, seteditObject] = useState(false); const [dragInsertRows, setdragInsertRows] = useState(false); const [dragInsertColums, setdragInsertColums] = useState(false); const [insrtRows, setinsrtRows] = useState(false); const [insertColumns, setinsertColumns] = useState(false); const [deleteRows, setdeleteRows] = useState(false); const [deleteColumn, setdeleteColumn] = useState(false); const [operateColumnOutline, setoperateColumnOutline] = useState(false); const [operateRowOutline, setoperateRowOutline] = useState(false); const [password, setPassword] = useState(''); const applySetting = () => { let option = { allowSelectLockedCells: selectLockedCells, allowSelectUnlockedCells: selectUnlockedCells, allowSort: sort, allowFilter: filter, allowResizeRows: resizeRows, allowResizeColumns: resizeColums, allowEditObjects: editObject, allowDragInsertRows: dragInsertRows, allowDragInsertColumns: dragInsertColums, allowInsertRows: insrtRows, allowInsertColumns: insertColumns, allowDeleteRows: deleteRows, allowDeleteColumns: deleteColumn, allowOutlineColumns: operateColumnOutline, allowOutlineRows: operateRowOutline }; let sheet = spread.getActiveSheet(); sheet.options.protectionOptions = option; } const _setProtectSheet = () => { let sheet = spread.getActiveSheet(); if (sheet.options.isProtected) { alert(alreadyProtect); return; } sheet.protect(password); setProtectSheet(true); setPassword(''); } const setUnprotectSheet = () => { let sheet = spread.getActiveSheet(); if (sheet.hasPassword()) { let success = sheet.unprotect(password); if (!success) { alert(passwordWrongTip); return; } } else { sheet.unprotect(); } setProtectSheet(false); setPassword(''); } const initSpread = (currSpread) => { spread = currSpread; let sheet = spread.getActiveSheet(); spread.suspendPaint(); let salesData = [ ['Salesperson', 'Region'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'], ['Erich', 'West'], ['Dafna', 'North'], ['Rob', 'South'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'], ['Erich', 'West'], ['Dafna', 'North'], ['Rob', 'South'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'] ]; sheet.setArray(0, 0, salesData); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 120); //unlocked cells let style = new GC.Spread.Sheets.Style(); style.locked = false; style.backColor = '#C3C3C3'; sheet.setStyle(-1, 8, style); sheet.setStyle(-1, 9, style); sheet.setStyle(15, -1, style); sheet.setStyle(16, -1, style); sheet.setStyle(8, 2, style); //locked cells let style2 = new GC.Spread.Sheets.Style(); style2.locked = true; style2.backColor = '#F4F8EB'; sheet.setStyle(13, -1, style2); sheet.setStyle(18, 8, style2); sheet.setStyle(0, 0, style2) sheet.setStyle(0, 1, style2); let filter = new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(1, 0, 100, 2)); sheet.rowFilter(filter); sheet.comments.add(5, 4, 'locked comment'); sheet.comments.add(22, 4, 'unlocked comment'); sheet.comments.get(5, 4).locked(true).displayMode(1); sheet.comments.get(22, 4).locked(false).displayMode(1).lockText(false); var _commandManager = spread.commandManager(); _commandManager.execute({ cmd: "outlineColumn", sheetName: sheet.name(), index: 11, count: 3 }); _commandManager.execute({ cmd: "outlineRow", sheetName: sheet.name(), index: 18, count: 3 }); spread.resumePaint(); let option = { allowSelectLockedCells: true, allowSelectUnlockedCells: true, allowFilter: true, allowSort: false, allowResizeRows: true, allowResizeColumns: false, allowEditObjects: false, allowDragInsertRows: false, allowDragInsertColumns: false, allowInsertRows: false, allowInsertColumns: false, allowDeleteRows: false, allowDeleteColumns: false }; sheet.options.protectionOptions = option; sheet.options.isProtected = true; } return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <div class="options-container"> <br /> <div class="option-row" style={{ height: '25px' }}> <img id="protectStatus" style={{ height: '25px' }} src={protectSheet ? protectImg : unprotectImg} /> </div> <div class="option-row"> <label for="protectPassword">Password (optional)</label> <input id="protectPassword" type="password" value={password} onChange={(e) => setPassword(e.target.value)} /> <input type="button" value="Protect" id="protectBtn" onClick={() => _setProtectSheet()} style={{ width: '100px' }} disabled={protectSheet} /> <input type="button" value="Unprotect" id="unprotectBtn" onClick={() => setUnprotectSheet()} style={{ width: '100px', marginLeft: '10px' }} disabled={!protectSheet} /> </div> <br /> <div class="option-row"> <label >Use following protection options to limit what the user can do in regards to editing the sheet.</label> </div> <div> <div class="option-row"> <input id="chkSelectLockedCells" onChange={(e) => setselectLockedCells(e.target.checked)} type="checkbox" checked={selectLockedCells} /> <label for="chkSelectLockedCells" class="sizedLabel">Select locked cells</label> </div> <div class="option-row"> <input id="chkSelectUnlockedCells" onChange={(e) => setselectUnlockedCells(e.target.checked)} type="checkbox" checked={selectUnlockedCells} /> <label for="chkSelectUnlockedCells" class="sizedLabel">Select unlocked cells</label> </div> <div class="option-row"> <input id="chkAllowSort" type="checkbox" onChange={(e) => setSort(e.target.checked)} checked={sort} /> <label for="chkAllowSort" class="sizedLabel">Sort</label> </div> <div class="option-row"> <input id="chkAllowFilter" type="checkbox" onChange={(e) => setfilter(e.target.checked)} checked={filter} /> <label for="chkAllowFilter" class="sizedLabel">Filter</label> </div> <div class="option-row"> <input id="chkAllowResizeRows" type="checkbox" onChange={(e) => setresizeRows(e.target.checked)} checked={resizeRows} /> <label for="chkAllowResizeRows" class="sizedLabel">Resize rows</label> </div> <div class="option-row"> <input id="chkAllowResizeColumns" type="checkbox" onChange={(e) => setresizeColums(e.target.checked)} checked={resizeColums} /> <label for="chkAllowResizeColumns" class="sizedLabel">Resize columns</label> </div> <div class="option-row"> <input id="chkAllowEditObjects" type="checkbox" onChange={(e) => seteditObject(e.target.checked)} checked={editObject} /> <label for="chkAllowEditObjects" class="sizedLabel">Edit objects</label> </div> <div class="option-row"> <input id="chkAllowDragInsertRows" type="checkbox" onChange={(e) => setdragInsertRows(e.target.checked)} checked={dragInsertRows} /> <label for="chkAllowDragInsertRows" class="sizedLabel">Drag insert rows</label> </div> <div class="option-row"> <input id="chkAllowDragInsertColumns" type="checkbox" onChange={(e) => setdragInsertColums(e.target.checked)} checked={dragInsertColums} /> <label for="chkAllowDragInsertColumns" class="sizedLabel">Drag insert columns</label> </div> <div class="option-row"> <input id="chkAllowInsertRows" type="checkbox" onChange={(e) => setinsrtRows(e.target.checked)} checked={insrtRows} /> <label for="chkAllowInsertRows" class="sizedLabel">Insert rows</label> </div> <div class="option-row"> <input id="chkAllowInsertColumns" type="checkbox" onChange={(e) => setinsertColumns(e.target.checked)} checked={insertColumns} /> <label for="chkAllowInsertColumns" class="sizedLabel">Insert columns</label> </div> <div class="option-row"> <input id="chkAllowDeleteRows" type="checkbox" onChange={(e) => setdeleteRows(e.target.checked)} checked={deleteRows} /> <label for="chkAllowDeleteRows" class="sizedLabel">Delete rows</label> </div> <div class="option-row"> <input id="chkAllowDeleteColumns" type="checkbox" onChange={(e) => setdeleteColumn(e.target.checked)} checked={deleteColumn} /> <label for="chkAllowDeleteColumns" class="sizedLabel">Delete columns</label> </div> <div class="option-row"> <input id="chkallowOutlineRows" type="checkbox" onChange={(e) => setoperateRowOutline(e.target.checked)} checked={operateRowOutline} /> <label for="chkallowOutlineRows" class="sizedLabel">Operate row outline</label> </div> <div class="option-row"> <input id="chkallowOutlineColumns" type="checkbox" onChange={(e) => setoperateColumnOutline(e.target.checked)} checked={operateColumnOutline} /> <label for="chkallowOutlineColumns" class="sizedLabel">Operate column outline</label> </div> <div class="option-row"> <input type="button" value="Set" id="setProtectionOptions" onClick={() => applySetting()} style={{ width: '100px' }} /> </div> <div class="option-row"> <label>Select the protection options and then click Set</label> </div> </div> </div> </div> ) }
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; const Component = React.Component; const passwordWrongTip = 'Password is not correct!'; const alreadyProtect = 'The worksheet is already protected!'; const unprotectImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB0UlEQVR4nO2YzU7CQBDHNyae9A30qF6NNlFv7QzhqheukN1An4Mbnv14A70YwgERX0XiWRNBKl8eMDGuGWy0LopoS0tl/8kkZLMT/r+dmW1axrS0tAKTYRjziJgCgFNEvAKAR0Tsub9pLUV72DTKsqw9ALhGRDkqaA/tZdOifD4/h4j7PxlX4gURC5QbtX/2B/PeKERqnlrBPU1vi/QR8dCyrO1kMrlAYZrmDgAcAcCTWgkA2I3EPA2j2vMAcAMA69/lJBKJDQC4VWfCiGKw6UZRT36UeU/e5heVSLGw5V6LXhMHv8g9VuBPWNhCxJoCsDVuLs2EkltjYct9QL2bME1zcdxc2qsA9FjYUq/EsPN9SwOgrsD4yuVyy5zzIue8K4SQkwz+9h8lzvlqkOadSRsXwyBOJpNZ8g1AJx+2efEBcRYEQDdCgLZvgKjMCzc0gNAVELqFfGkmW8i2bXl5cS7bTkO2mnVZrZQHa7EBqFbKUj73PwWtxQag7TSGAGgtNgCtZn0I4OH+Lj4A1bi3kG3bA8NUiVgOsQgwmAYQugJSt9Cst1An7q+UpQgBir4B0un0mhCiGYF5J5vNrrAgRN9n6BNHSO3UoZMPzLyW1j/XK1zJDTLJ864hAAAAAElFTkSuQmCC'; const protectImg = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB10lEQVR4nO2Yz0rDQBDGB0Ev+gZ6VK+iAfWWzJRe9dL3qfVQlWwR/7yBXqT0JepD2Nar0h4s2ERq3YArW4LGrdZq0qSx+8FACDvw/XZmNmQBtLS0IpNhGLNElEPESyK6QcQnInL9Z/kuJ9fAJMqyrF1EbBCRGBZyjVwLk6J8Pj9DRAc/GVfilYiKMjdp//AH88EoJmpetoK/m8EW6RHRqWVZW9lsdl6GaZrbiHiGiC9qJRBxJxHzchjVnkfEO0Rc+y4nk8msI+K9OhNGEoMtTxR154eZD+RtfFGJHMQt/1gMmjj5Re65An8BcYuIagrA5qi5ciaU3BrELf8D9W7CNM2FUXPlWgXAhbilHolx54eWBiBdgdElDmGJMyhzBo7HQIwzOAOHM6j0jmAlOvM2tMdt3FNBbGiLEiyGBpA7H7d576MaV1EAOAkCPIYGSMq854cG8HQFQLdQKE1nCx3Pie71vnBbDeE266JbLfTfpQagWy0Ix3E+RR8iLQBuqzEA4LZuUwTQrA8CNGtpb6G9lA1xtdCvRCqH2IswQAMwXQGhW2iqW4jb0En1LyVnUEkQoBwaoMdglTN4iN28De3nEixDFJL3M/KKI4524jZ05M5HZl5L65/rDc6nQtkkwmMVAAAAAElFTkSuQmCC'; export class App extends Component { constructor(props) { super(props); this.spread = null; this.state = { protectSheet: true, selectLockedCells: true, selectUnlockedCells: true, sort: false, filter: true, resizeRows: true, resizeColums: false, editObject: false, dragInsertRows: false, dragInsertColums: false, insrtRows: false, insertColumns: false, deleteRows: false, deleteColumn: false, operateColumnOutline: false, operateRowOutline: false, password: '' } } render() { const { protectSheet, selectLockedCells, selectUnlockedCells, sort, filter, resizeRows, resizeColums, editObject, dragInsertRows, dragInsertColums, insrtRows, insertColumns, deleteRows, deleteColumn, operateColumnOutline, operateRowOutline, password} = this.state; return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <div class="options-container"> <br /> <div class="option-row" style={{height: '25px'}}> <img id="protectStatus" style={{height: '25px'}} src={protectSheet ? protectImg : unprotectImg}/> </div> <div class="option-row"> <label for="protectPassword">Password (optional)</label> <input id="protectPassword" type="password" value={password} onChange={(e)=>this.setState({password: e.target.value})}/> <input type="button" value="Protect" id="protectBtn" onClick={()=>{this.setProtectSheet()}} style={{width:'100px'}} disabled={protectSheet}/> <input type="button" value="Unprotect" id="unprotectBtn" onClick={()=>{this.setUnprotectSheet()}} style={{width:'100px', marginLeft: '10px'}} disabled={!protectSheet}/> </div> <br /> <div class="option-row"> <label >Use following protection options to limit what the user can do in regards to editing the sheet.</label> </div> <div> <div class="option-row"> <input id="chkSelectLockedCells" onChange={(e) => { this.setselectLockedCells(e.target.checked) }} type="checkbox" checked={selectLockedCells} /> <label for="chkSelectLockedCells" class="sizedLabel">Select locked cells</label> </div> <div class="option-row"> <input id="chkSelectUnlockedCells" onChange={(e) => { this.setselectUnlockedCells(e.target.checked) }} type="checkbox" checked={selectUnlockedCells} /> <label for="chkSelectUnlockedCells" class="sizedLabel">Select unlocked cells</label> </div> <div class="option-row"> <input id="chkAllowSort" type="checkbox" onChange={(e) => { this.setSort(e.target.checked) }} checked={sort} /> <label for="chkAllowSort" class="sizedLabel">Sort</label> </div> <div class="option-row"> <input id="chkAllowFilter" type="checkbox" onChange={(e) => { this.setfilter(e.target.checked) }} checked={filter} /> <label for="chkAllowFilter" class="sizedLabel">Filter</label> </div> <div class="option-row"> <input id="chkAllowResizeRows" type="checkbox" onChange={(e) => { this.setresizeRows(e.target.checked) }} checked={resizeRows} /> <label for="chkAllowResizeRows" class="sizedLabel">Resize rows</label> </div> <div class="option-row"> <input id="chkAllowResizeColumns" type="checkbox" onChange={(e) => { this.setresizeColums(e.target.checked) }} checked={resizeColums} /> <label for="chkAllowResizeColumns" class="sizedLabel">Resize columns</label> </div> <div class="option-row"> <input id="chkAllowEditObjects" type="checkbox" onChange={(e) => { this.seteditObject(e.target.checked) }} checked={editObject} /> <label for="chkAllowEditObjects" class="sizedLabel">Edit objects</label> </div> <div class="option-row"> <input id="chkAllowDragInsertRows" type="checkbox" onChange={(e) => { this.setdragInsertRows(e.target.checked) }} checked={dragInsertRows} /> <label for="chkAllowDragInsertRows" class="sizedLabel">Drag insert rows</label> </div> <div class="option-row"> <input id="chkAllowDragInsertColumns" type="checkbox" onChange={(e) => { this.setdragInsertColums(e.target.checked) }} checked={dragInsertColums} /> <label for="chkAllowDragInsertColumns" class="sizedLabel">Drag insert columns</label> </div> <div class="option-row"> <input id="chkAllowInsertRows" type="checkbox" onChange={(e) => { this.setinsrtRows(e.target.checked) }} checked={insrtRows} /> <label for="chkAllowInsertRows" class="sizedLabel">Insert rows</label> </div> <div class="option-row"> <input id="chkAllowInsertColumns" type="checkbox" onChange={(e) => { this.setinsertColumns(e.target.checked) }} checked={insertColumns} /> <label for="chkAllowInsertColumns" class="sizedLabel">Insert columns</label> </div> <div class="option-row"> <input id="chkAllowDeleteRows" type="checkbox" onChange={(e) => { this.setdeleteRows(e.target.checked) }} checked={deleteRows} /> <label for="chkAllowDeleteRows" class="sizedLabel">Delete rows</label> </div> <div class="option-row"> <input id="chkAllowDeleteColumns" type="checkbox" onChange={(e) => { this.setdeleteColumn(e.target.checked) }} checked={deleteColumn} /> <label for="chkAllowDeleteColumns" class="sizedLabel">Delete columns</label> </div> <div class="option-row"> <input id="chkallowOutlineRows" type="checkbox" onChange={(e) => { this.setoperateRowOutline(e.target.checked) }} checked={operateRowOutline} /> <label for="chkallowOutlineRows" class="sizedLabel">Operate row outline</label> </div> <div class="option-row"> <input id="chkallowOutlineColumns" type="checkbox" onChange={(e) => { this.setoperateColumnOutline(e.target.checked) }} checked={operateColumnOutline} /> <label for="chkallowOutlineColumns" class="sizedLabel">Operate column outline</label> </div> <div class="option-row"> <input type="button" value="Set" id="setProtectionOptions" onClick={() => { this.applySetting() }} style={{ width: '100px' }} /> </div> <div class="option-row"> <label>Select the protection options and then click Set</label> </div> </div> </div> </div> ) } applySetting() { let option = { allowSelectLockedCells: this.state.selectLockedCells, allowSelectUnlockedCells: this.state.selectUnlockedCells, allowSort: this.state.sort, allowFilter: this.state.filter, allowResizeRows: this.state.resizeRows, allowResizeColumns: this.state.resizeColums, allowEditObjects: this.state.editObject, allowDragInsertRows: this.state.dragInsertRows, allowDragInsertColumns: this.state.dragInsertColums, allowInsertRows: this.state.insrtRows, allowInsertColumns: this.state.insertColumns, allowDeleteRows: this.state.deleteRows, allowDeleteColumns: this.state.deleteColumn, allowOutlineColumns: this.state.operateColumnOutline, allowOutlineRows: this.state.operateRowOutline }; let sheet = this.spread.getActiveSheet(); sheet.options.protectionOptions = option; } setselectLockedCells(value) { this.setState({ selectLockedCells: value }) } setselectUnlockedCells(value) { this.setState({ selectUnlockedCells: value }) } setSort(value) { this.setState({ sort: value }) } setfilter(value) { this.setState({ filter: value }) } setresizeRows(value) { this.setState({ resizeRows: value }) } setresizeColums(value) { this.setState({ resizeColums: value }) } seteditObject(value) { this.setState({ editObject: value }) } setdragInsertRows(value) { this.setState({ dragInsertRows: value }) } setdragInsertColums(value) { this.setState({ dragInsertColums: value }) } setinsrtRows(value) { this.setState({ insrtRows: value }) } setinsertColumns(value) { this.setState({ insertColumns: value }) } setdeleteRows(value) { this.setState({ deleteRows: value }) } setdeleteColumn(value) { this.setState({ deleteColumn: value }) } setoperateColumnOutline(value) { this.setState({ operateColumnOutline: value }) } setoperateRowOutline(value) { this.setState({ operateRowOutline: value }) } setProtectSheet() { let sheet = this.spread.getActiveSheet(); if (sheet.options.isProtected) { alert(alreadyProtect); return ; } const password = this.state.password; sheet.protect(password); this.setState({ protectSheet: true, password: '' }); } setUnprotectSheet() { const password = this.state.password; let sheet = this.spread.getActiveSheet(); if (sheet.hasPassword()) { let success = sheet.unprotect(password); if (!success) { alert(passwordWrongTip); return ; } } else { sheet.unprotect(); } this.setState({ protectSheet: false, password: '' }); } initSpread(spread) { this.spread = spread; let sheet = spread.getActiveSheet(); spread.suspendPaint(); let salesData = [ ['Salesperson', 'Region'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'], ['Erich', 'West'], ['Dafna', 'North'], ['Rob', 'South'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'], ['Erich', 'West'], ['Dafna', 'North'], ['Rob', 'South'], ['Joe', 'North'], ['Robert', 'South'], ['Michelle', 'East'] ]; sheet.setArray(0, 0, salesData); sheet.setColumnWidth(0, 120); sheet.setColumnWidth(1, 120); //unlocked cells let style = new GC.Spread.Sheets.Style(); style.locked = false; style.backColor = '#C3C3C3'; sheet.setStyle(-1, 8, style); sheet.setStyle(-1, 9, style); sheet.setStyle(15, -1, style); sheet.setStyle(16, -1, style); sheet.setStyle(8, 2, style); //locked cells let style2 = new GC.Spread.Sheets.Style(); style2.locked = true; style2.backColor = '#F4F8EB'; sheet.setStyle(13, -1, style2); sheet.setStyle(18, 8, style2); sheet.setStyle(0, 0, style2) sheet.setStyle(0, 1, style2); let filter = new GC.Spread.Sheets.Filter.HideRowFilter(new GC.Spread.Sheets.Range(1, 0, 100, 2)); sheet.rowFilter(filter); sheet.comments.add(5, 4, 'locked comment'); sheet.comments.add(22, 4, 'unlocked comment'); sheet.comments.get(5, 4).locked(true).displayMode(1); sheet.comments.get(22, 4).locked(false).displayMode(1).lockText(false); var _commandManager = spread.commandManager(); _commandManager.execute({ cmd: "outlineColumn", sheetName: sheet.name(), index: 11, count: 3 }); _commandManager.execute({ cmd: "outlineRow", sheetName: sheet.name(), index: 18, count: 3 }); spread.resumePaint(); let option = { allowSelectLockedCells: true, allowSelectUnlockedCells: true, allowFilter: true, allowSort: false, allowResizeRows: true, allowResizeColumns: false, allowEditObjects: false, allowDragInsertRows: false, allowDragInsertColumns: false, allowInsertRows: false, allowInsertColumns: false, allowDeleteRows: false, allowDeleteColumns: false }; sheet.options.protectionOptions = option; sheet.options.isProtected = true; } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/en/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
.sizedLabel { display: inline-block; width: 180px; } .colorLabel { background-color: #F4F8EB; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; } label { margin-bottom: 6px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/umd/react.production.min.js', 'react-dom': 'npm:react-dom/umd/react-dom.production.min.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);