月份选择器

月份选择器是SpreadJS中的一种下拉菜单。 月份选择器定义在单元格样式中, 通过它用户可以更容易地选择月份。

下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。 SpreadJS目前拥有8种下拉列表,当前介绍的是月份选择器下拉列表。 你可以像如下代码一样使用月份选择器: 月份选择器下拉列表有以下选项: startYear: number : 指定月份选择器的起始年份,默认值为当前时间的十年前。 stopYear: number : 指定月份选择器的终止年份,默认值为当前年份。 height: number : 指定月份选择器视窗的高度,默认是300。
var spreadNS = GC.Spread.Sheets; window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); }; function initSpread(spread) { var sheet = spread.getSheet(0); sheet.suspendPaint(); // -------------------- 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(1, 5, "Month Picker"); sheet.setStyle(2, 5, monthPickerStyle); // -------------------- 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: 1970, stopYear: 2030, height: 400, } } ]; sheet.setText(1, 11, "Month Picker"); sheet.setStyle(2, 11, monthPickerStyle); sheet.resumePaint(); spread.commandManager().execute({cmd:"openMonthPicker",row:2,col:5,sheetName:"Sheet1"}); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.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" style="width:100%; height: 100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }