日期时间选择器

日期时间选择器是SpreadJS中的一种下拉菜单,日期时间选择器下拉菜单定义在样式中,通过日期时间选择器用户可以方便地选择日期时间。

下拉菜单使开发人员能够向工作簿中的单元格添加具有特定属性的下拉菜单。 这些下拉菜单不需要任何额外的代码,只需指定要使用哪一种下拉菜单即可。 SpreadJS目前拥有9种下拉列表,当前介绍的是日期时间选择器下拉列表。 你可以使用日期时间选择器下拉列表,如以下代码所示: 日期时间选择器下拉列表有以下选项: showTime: boolean : 指定日历是否需要显示时间部分。 calendarPage: CalendarPage : 指定日历默认显示的内容,这个值可以是年,月,日,例如: calendarPage: GC.Spread.Sheets.CalendarPage.year. startDay: CalendarStartDay : 指定一周的起始日期,通常一周的起始日期是周一或者周日,用户可以通过这个选项设置一周内的任一天为起始日期,例如:startDay: GC.Spread.Sheets.CalendarStartDay.monday. showDateRange: boolean:指定日历是否需要显示为日期范围模式,默认值为false。 showBuiltInDateRange: boolean:指定日历是否需要显示内置的日期范围面板。
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(); // -------------------- Date Time Picker : showTime true --------------------- 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(1, 3, "Date Time Picker (showTime: true)"); sheet.setColumnWidth(3, 200); sheet.setStyle(2, 3, showTimeStyle); // -------------------- Date Time Picker : showTime False --------------------- let notShowTimestyle = new GC.Spread.Sheets.Style(); notShowTimestyle.formatter = 'm/d/yyyy'; notShowTimestyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; notShowTimestyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: false } } ]; sheet.setText(20, 3, "Date Time Picker (showTime: false)"); sheet.setStyle(21, 3, notShowTimestyle); // -------------------- Date Time Picker : CalendarPage - Year --------------------- let calendarYearStyle = new GC.Spread.Sheets.Style(); calendarYearStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarYearStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.year, } } ]; sheet.setText(20, 6, "Date Time picker (calendarPage - Year)"); sheet.setColumnWidth(6, 200); sheet.setStyle(21, 6, calendarYearStyle); // -------------------- Date Time Picker : CalendarPage - Month --------------------- let calendarMonthStyle = new GC.Spread.Sheets.Style(); calendarMonthStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; calendarMonthStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showTime: true, calendarPage: GC.Spread.Sheets.CalendarPage.month, } } ]; sheet.setText(1, 6, "Date Time picker (calendarPage - Month)"); sheet.setColumnWidth(6, 200); sheet.setStyle(2, 6, calendarMonthStyle); let rangeCalendarStyle = new GC.Spread.Sheets.Style(); rangeCalendarStyle.formatter = '=IF(ISBLANK(@), "", TEXT(@.start, "m/d/yyyy")&"~"&TEXT(@.end, "m/d/yyyy"))'; rangeCalendarStyle.cellButtons = [ { imageType: GC.Spread.Sheets.ButtonImageType.dropdown, command: "openDateTimePicker", useButtonStyle: true, } ]; rangeCalendarStyle.dropDowns = [ { type: GC.Spread.Sheets.DropDownType.dateTimePicker, option: { showDateRange: true, } } ]; sheet.setText(1, 10, "Date Range picker"); sheet.setColumnWidth(9, 100); sheet.setText(3, 9, "Start Time:"); sheet.setFormula(3, 10, '=IF(ISBLANK(K3), "", TEXT(K3.start, "m/d/yyyy")'); sheet.setText(4, 9, "End Time:"); sheet.setFormula(4, 10, '=IF(ISBLANK(K3), "", TEXT(K3.end, "m/d/yyyy")'); sheet.setText(1, 10, "Date Range picker"); sheet.setColumnWidth(10, 200); sheet.setStyle(2, 10, rangeCalendarStyle); sheet.resumePaint(); spread.commandManager().execute({ cmd: "openDateTimePicker", row: 2, col: 10, sheetName: "Sheet1" }); // spread.commandManager().execute({cmd:"openDateTimePicker",row:2,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,col:11,sheetName:"Sheet1"}); // spread.commandManager().execute({cmd:"openDateTimePicker",row:21,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; }