SpreadJS 13
SpreadJS Documentation / Developer's Guide / Features / Manage User Interface / Auto Fill Data / Auto Fill Dates
In This Topic
    Auto Fill Dates
    In This Topic

    SpreadJS allows users to automatically fill dates in the worksheet by using the drag fill option.

    You can simply drag the fill handle in an upward or downward direction to fill days, weekdays, months and years across the entire column in the worksheet. Also, you can quickly carry out other custom date filling operations like filling the first day of the month, filling the same day of the month, filling the last day of the month etc. as shown in the example shared below.

    Autofill dates

    Using Code

    Refer to the following example code in order to automatically fill the first day of the month and the last day of the month.

    JavaScript
    Copy Code
    // Initializing Spread
    var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'),
    { sheetCount: 1 });
    
    // Drag Fill Dates
    var sheet1 = spread.getSheet(0);
    sheet1.name("Date DragFill");
    sheet1.setValue(0, 0, 'Please drag up or down');
    sheet1.setValue(1, 0, 'First day of month to dragfill');
    sheet1.setColumnWidth(0, 80);
    sheet1.setValue(6, 0, new Date(2018, 3, 1));
    sheet1.setValue(7, 0, new Date(2018, 4, 1));
    sheet1.getRange(6, 0, 2, 1).formatter('m/d/yyyy');
    sheet1.setColumnWidth(1, 80);
    sheet1.setValue(6, 1, new Date(2017, 11, 1));
    sheet1.setValue(7, 1, new Date(2018, 0, 1));
    sheet1.getRange(6, 1, 2, 1).formatter('m/d/yyyy');
    sheet1.setValue(1, 3, 'Last day of month to dragfill');
    sheet1.setColumnWidth(3, 80);
    sheet1.setValue(6, 3, new Date(2018, 2, 31));
    sheet1.setValue(7, 3, new Date(2018, 3, 30));
    sheet1.getRange(6, 3, 2, 1).formatter('m/d/yyyy');
    sheet1.setColumnWidth(4, 80);
    sheet1.setValue(6, 4, new Date(2017, 11, 31));
    sheet1.setValue(7, 4, new Date(2018, 0, 31));
    sheet1.getRange(6, 4, 2, 1).formatter('m/d/yyyy');