You can set allow/disallow edit in cell using the allowEditIncell proprity of Style.
The following code will disable enter edit mode in a cell for editing.
The following code will disable enter edit mode in a cell range for editing.
The following code will disable tab stop on cell.
The following code will disable tab stop on cell range.
var spreadNS = GC.Spread.Sheets;
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
spread.setSheetCount(1);
var sheet = spread.getSheet(0);
initSheet(sheet, false);
var btn = document.getElementById("set-style");
btn.addEventListener("click", function () {
var sheet = spread.getActiveSheet();
var range = sheet.getSelections()[0];
var cellRange = sheet.getRange(range.row,range.col,range.rowCount,range.colCount);
var allowEditInCell = document.getElementById("allowEditInCell").checked
cellRange.allowEditInCell(allowEditInCell);
});
var btn = document.getElementById("set-tab-stop");
btn.addEventListener("click", function () {
var sheet = spread.getActiveSheet();
var range = sheet.getSelections()[0];
var cellRange = sheet.getRange(range.row,range.col,range.rowCount,range.colCount);
var tabStop = document.getElementById("tab-stop").checked
cellRange.tabStop(tabStop);
});
};
function initSheet(sheet, multiSelect) {
sheet.suspendPaint();
sheet.setColumnWidth(1, 120);
sheet.setColumnWidth(2, 200);
sheet.setColumnWidth(4, 120);
sheet.setColumnWidth(5, 300);
sheet.setValue(1, 1, "Cell Types:");
sheet.getCell(1, 1).fontWeight("bold");
// -------------------- checkbox ---------------------
sheet.setValue(2, 1, "Checkbox");
sheet.getCell(2, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
var captionCellType = new GC.Spread.Sheets.CellTypes.CheckBox();
captionCellType.caption("Checkbox");
sheet.setCellType(2, 2, captionCellType);
sheet.getCell(2, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// -------------------- checkbox list ---------------------
sheet.setValue(2, 4, "Checkbox List");
sheet.getCell(2, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
var checkBoxList = new GC.Spread.Sheets.CellTypes.CheckBoxList();
checkBoxList.items([
{ text: "Checkbox1", value: "0" },
{ text: "Checkbox2", value: "1" },
{ text: "Checkbox3", value: "2" },
]);
sheet.setCellType(2, 5, checkBoxList);
// -------------------- combox cell type ---------------------
var combo = new spreadNS.CellTypes.ComboBox();
combo.items([{ text: "Oranges", value: "11k" }, { text: "Apples", value: "15k" }, { text: "Grape", value: "100k" }])
.editorValueType(spreadNS.CellTypes.EditorValueType.text);
sheet.getCell(4, 2, spreadNS.SheetArea.viewport).cellType(combo).value("Apples");
sheet.getCell(4, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.setValue(4, 1, "ComboBox");
sheet.getCell(4, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
// -------------------- radio cell type ---------------------
var radio = new GC.Spread.Sheets.CellTypes.RadioButtonList();
radio.items([
{ text: "Radio1", value: "0" },
{ text: "Radio2", value: "1" },
{ text: "Radio3", value: "2" },
]);
sheet.setCellType(4, 5, radio);
sheet.getCell(4, 5).vAlign(GC.Spread.Sheets.VerticalAlign.center);
sheet.setValue(4, 4, "Radio");
sheet.getCell(4, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
// -------------------- HyperLink cell type ---------------------
var h1 = new spreadNS.CellTypes.HyperLink();
h1.text("SpreadJS Overview");
sheet.setCellType(6, 2, h1, spreadNS.SheetArea.viewport);
sheet.getCell(6, 2, spreadNS.SheetArea.viewport).value("http://developer.mescius.com/en/spreadjs/").vAlign(spreadNS.HorizontalAlign.center);
sheet.setValue(6, 1, "Hyperlink:");
sheet.getCell(6, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setValue(9, 1, "Cell Dropdowns:");
sheet.getCell(9, 1).fontWeight("bold");
// -------------------- Vertical text list ---------------------
var verticalStyle = new GC.Spread.Sheets.Style();
verticalStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openList",
useButtonStyle: true,
}
];
verticalStyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.list,
option: {
multiSelect: multiSelect,
items: [
{
text: 'item1',
value: 'item1'
},
{
text: 'item2',
value: 'item2'
},
{
text: 'item3',
value: 'item3'
},
{
text: 'item4',
value: 'item4'
}
],
}
}
];
sheet.setText(10, 1, "Dropdown List");
sheet.getCell(10, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(10, 2, verticalStyle);
sheet.getCell(10, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// -------------------------- time picker -----------------------
sheet.setText(10, 4, "Time Picker");
sheet.getCell(10, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
function createPickerStyle(option) {
var timePickerStyle = new GC.Spread.Sheets.Style();
timePickerStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openTimePicker",
useButtonStyle: true,
}
];
timePickerStyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.timePicker,
option: option
}
];
return timePickerStyle;
}
sheet.setStyle(10, 5, createPickerStyle({
min: { hour: 8 },
max: { hour: 19 },
step: { minute: 30 },
formatString: "h:mm AM/PM",
}));
sheet.getCell(10, 5).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// -------------------- Month Picker ---------------------
var monthPickerStyle = new GC.Spread.Sheets.Style();
monthPickerStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openMonthPicker",
useButtonStyle: true,
}
];
monthPickerStyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.monthPicker,
option: {
startYear: 2009,
stopYear: 2019,
height: 300,
}
}
];
sheet.setText(12, 1, "Month Picker");
sheet.getCell(12, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(12, 2, monthPickerStyle);
sheet.getCell(12, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// -------------------- Date Time Picker ---------------------
var showTimeStyle = new GC.Spread.Sheets.Style();
showTimeStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openDateTimePicker",
useButtonStyle: true,
}
];
showTimeStyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.dateTimePicker,
option: {
showTime: true
}
}
];
sheet.setText(12, 4, "Date Time Picker");
sheet.getCell(12, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(12, 5, showTimeStyle);
sheet.getCell(12, 5).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// --------------------------- Slider ---------------------------
function createSliderStyle(option) {
let sliderStyle = new GC.Spread.Sheets.Style();
sliderStyle.cellButtons = [{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openSlider",
useButtonStyle: true
}];
sliderStyle.dropDowns = [{
type: GC.Spread.Sheets.DropDownType.slider,
option: option
}];
return sliderStyle
}
sheet.setText(14, 1, "Slider");
sheet.getCell(14, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(14, 2, createSliderStyle({
max: 45,
min: 32,
marks: ["36"],
step: 1,
direction: GC.Spread.Sheets.LayoutDirection.vertical,
formatString: "0°C"
}));
sheet.getCell(14, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// --------------------------- Calculator ---------------------------
var calculatorStyle = new GC.Spread.Sheets.Style();
calculatorStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openCalculator",
useButtonStyle: true,
}
];
sheet.setText(14, 4, "Calculator");
sheet.getCell(14, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(14, 5, calculatorStyle);
sheet.getCell(14, 5).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// --------------------------- Color Picker ---------------------------
var colorStyle = new GC.Spread.Sheets.Style();
colorStyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openColorPicker",
useButtonStyle: true,
}
];
sheet.setText(16, 1, "Color Picker");
sheet.getCell(16, 1).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(16, 2, colorStyle);
sheet.getCell(16, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// -------------------- WorkFlow ---------------------
let workFlowstyle = new GC.Spread.Sheets.Style();
workFlowstyle.cellButtons = [
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
command: "openWorkflowList",
useButtonStyle: true,
}
];
workFlowstyle.dropDowns = [
{
type: GC.Spread.Sheets.DropDownType.workflowList,
option: {
items: [
{ value: "New", transitions: [1] },
{ value: "Open",transitions: [0,2,3,5] },
{ value: "In Progress", transitions: [1, 3, 5] },
{ value: "Resolved", transitions: [5, 4] },
{ value: "Reopened",transitions: [5, 3, 2] },
{ value: "Closed", transitions: [4] },
]
}
}
];
sheet.setText(16, 4, "Workflow List");
sheet.getCell(16, 4).vAlign(GC.Spread.Sheets.VerticalAlign.center).foreColor("green");
sheet.setStyle(16, 5, workFlowstyle);
sheet.getCell(16, 5).vAlign(GC.Spread.Sheets.VerticalAlign.center);
// --------------------------------------------------------------
sheet.bind(GC.Spread.Sheets.Events.SelectionChanged, onSelectionChanged.bind(sheet));
sheet.resumePaint();
}
function onSelectionChanged(eventName, args) {
var sheet = this;
var range = args.newSelections[0];
var cellRange = sheet.getRange(range.row,range.col,range.rowCount,range.colCount);
var allowEditInCell = cellRange.allowEditInCell();
var tabStop = cellRange.tabStop();
document.getElementById("allowEditInCell").checked = allowEditInCell !== false;
document.getElementById("tab-stop").checked = tabStop !== false;
}
<!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/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/en/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<p>Uncheck the option below to disable entering edit mode to edit cell.</p>
<div class="settings-row">
<label>
<input id="allowEditInCell" type="checkbox"/>
Allow Edit In Cell
</label>
</div>
<div class="settings-row settings-button">
<button id="set-style" class="settings-btn">Set Allow Edit in Cell</button>
</div>
<p>Uncheck the option below to disable tab stop on cell.</p>
<div class="settings-row">
<label>
<input id="tab-stop" type="checkbox"/>
Tab Stop
</label>
</div>
<div class="settings-row settings-button">
<button id="set-tab-stop" class="settings-btn">Set Tab Stop</button>
</div>
</div>
</div>
</body>
</html>
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.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;
}
.settings-row {
width: 100%;
height: 30px;
font-size: 13px;
}
.settings-button {
margin-top: 15px;
}
label {
margin-bottom: 6px;
}
input {
padding: 4px 6px;
}
.settings-btn {
display: inline-block;
width: 220px;
height: 21px;
}