カスタムフィル

マウスのドラッグアクションだけでなく、自動入力されるデータもカスタマイズできます。これにより、実行時にも自動入力できるため、データベースからロードしたデータをどのように入力するか、カスタマイズしたい場合などに便利です。

自動入力されるデータには、次の5つのタイプがあります。 Auto: オートフィルタイプ Direction: 方向フィルタイプ Linear: 加算フィルタイプ Growth: 乗算フィルタイプ Date: 日付フィルタイプ Spread.Sheetsには、それぞれのタイプのオートフィルを実行するメソッドがあります。
window.onload = function () { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), {sheetCount: 1}); initSpread(spread); }; function initSpread(spread) { var startRangeFormulaTextBox = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('startRange'), {rangeSelectMode: true}); var wholeRangeFormulaTextBox = new GC.Spread.Sheets.FormulaTextBox.FormulaTextBox(document.getElementById('wholeRange'), {rangeSelectMode: true}); startRangeFormulaTextBox.workbook(spread); wholeRangeFormulaTextBox.workbook(spread); spread.options.newTabVisible = false; var sheet = spread.getSheet(0); sheet.setValue(0, 0, 1); _getElementById("fillDirectionSet").style.display='none'; _getElementById("fillDateUnitSet").style.display='none'; _getElementById("fillStepAndStop").style.display='none'; _getElementById("btnFillAutobyDirection").style.display='none'; _getElementById("btnFillLinear").style.display='none'; _getElementById("btnFillGrowth").style.display='none'; _getElementById("btnFillDate").style.display='none'; _getElementById("fillMethods").addEventListener('change',function () { switch (_getElementById("fillMethods").value) { case '0': _getElementById("fillSeriesSet").style.display='block'; _getElementById("btnFillAuto").style.display='block'; _getElementById("fillDateUnitSet").style.display='none'; _getElementById("fillDirectionSet").style.display='none'; _getElementById("btnFillAutobyDirection").style.display='none'; _getElementById("btnFillLinear").style.display='none'; _getElementById("btnFillGrowth").style.display='none'; _getElementById("btnFillDate").style.display='none'; _getElementById("fillStepAndStop").style.display='none'; break; case '1': _getElementById("fillDirectionSet").style.display='block'; _getElementById("btnFillAutobyDirection").style.display='block'; _getElementById("fillDateUnitSet").style.display='none'; _getElementById("fillSeriesSet").style.display='none'; _getElementById("btnFillAuto").style.display='none'; _getElementById("btnFillLinear").style.display='none'; _getElementById("btnFillGrowth").style.display='none'; _getElementById("btnFillDate").style.display='none'; _getElementById("fillStepAndStop").style.display='none'; break; case '2': _getElementById("fillSeriesSet").style.display='block'; _getElementById("btnFillLinear").style.display='block'; _getElementById("fillStepAndStop").style.display='block'; _getElementById("fillDateUnitSet").style.display='none'; _getElementById("fillDirectionSet").style.display='none'; _getElementById("btnFillAuto").style.display='none'; _getElementById("btnFillAutobyDirection").style.display='none'; _getElementById("btnFillGrowth").style.display='none'; _getElementById("btnFillDate").style.display='none'; break; case '3': _getElementById("fillSeriesSet").style.display='block'; _getElementById("btnFillGrowth").style.display='block'; _getElementById("fillStepAndStop").style.display='block'; _getElementById("fillDateUnitSet").style.display='none'; _getElementById("fillDirectionSet").style.display='none'; _getElementById("btnFillAuto").style.display='none'; _getElementById("btnFillAutobyDirection").style.display='none'; _getElementById("btnFillLinear").style.display='none'; _getElementById("btnFillDate").style.display='none'; break; case '4': _getElementById("fillSeriesSet").style.display='block'; _getElementById("btnFillDate").style.display='block'; _getElementById("fillStepAndStop").style.display='block'; _getElementById("fillDateUnitSet").style.display='block'; _getElementById("fillDirectionSet").style.display='none'; _getElementById("btnFillAuto").style.display='none'; _getElementById("btnFillAutobyDirection").style.display='none'; _getElementById("btnFillGrowth").style.display='none'; _getElementById("btnFillLinear").style.display='none'; break; } }); _getElementById("btnFillAuto").addEventListener('click',function() { var sheet = spread.getActiveSheet(); var startRange = getRange(sheet, startRangeFormulaTextBox.text()); var wholeRange = getRange(sheet, wholeRangeFormulaTextBox.text()); if(parseInt(_getElementById("fillSeries").value) === 1) { wholeRange.rowCount = startRange.rowCount; } else { wholeRange.colCount = startRange.colCount; } sheet.fillAuto(startRange, wholeRange, { series: parseInt(_getElementById("fillSeries").value), fillType: GC.Spread.Sheets.Fill.FillType.auto }); }); _getElementById("btnFillAutobyDirection").addEventListener('click',function () { var sheet = spread.getActiveSheet(); var startRange = getRange(sheet, startRangeFormulaTextBox.text()); var wholeRange = getRange(sheet, wholeRangeFormulaTextBox.text()); sheet.fillAuto(startRange, wholeRange, { direction: parseInt(_getElementById("fillDirection").value), fillType: GC.Spread.Sheets.Fill.FillType.direction }); }); _getElementById("btnFillLinear").addEventListener('click',function () { var sheet = spread.getActiveSheet(); var startRange = getRange(sheet, startRangeFormulaTextBox.text()); var wholeRange = getRange(sheet, wholeRangeFormulaTextBox.text()); var step = parseInt(_getElementById("step").value); var stopString = _getElementById("stop").value; var stop; if (stopString !== '') { stop = parseInt(stopString); } sheet.fillAuto(startRange, wholeRange, { series: parseInt(_getElementById("fillSeries").value), step: step, stop: stop, fillType: GC.Spread.Sheets.Fill.FillType.linear }); }); _getElementById("btnFillGrowth").addEventListener('click',function () { var sheet = spread.getActiveSheet(); var startRange = getRange(sheet, startRangeFormulaTextBox.text()); var wholeRange = getRange(sheet, wholeRangeFormulaTextBox.text()); var step = parseInt(_getElementById("step").value); var stopString = _getElementById("stop").value; var stop; if (stopString !== '') { stop = parseInt(stopString); } sheet.fillAuto(startRange, wholeRange, { series: parseInt(_getElementById("fillSeries").value), step: step, stop: stop, fillType: GC.Spread.Sheets.Fill.FillType.growth }); }); _getElementById("btnFillDate").addEventListener('click',function () { var sheet = spread.getActiveSheet(); var startRange = getRange(sheet, startRangeFormulaTextBox.text()); var wholeRange = getRange(sheet, wholeRangeFormulaTextBox.text()); var step = parseInt(_getElementById("step").value); var stop = null; if (_getElementById("stop").value !== '') { stop = new Date(_getElementById("stop").value); } sheet.fillAuto(startRange, wholeRange, { series: parseInt(_getElementById("fillSeries").value), unit: parseInt(_getElementById("fillDateUnit").value), step: step, stop: stop, fillType: GC.Spread.Sheets.Fill.FillType.date }); }); }; function getRange(sheet, rangeString) { try{ var rangeObject = GC.Spread.Sheets.CalcEngine.formulaToExpression(sheet, rangeString).getRange(0, 0); var range = new GC.Spread.Sheets.Range(rangeObject.row, rangeObject.col, rangeObject.rowCount, rangeObject.colCount); return range; }catch (e){ throw new Error("Select Ranges are not right"); } } function _getElementById(id){ return document.getElementById(id); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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> [範囲の開始位置]フィールドを使用して、フィルを開始するセル範囲を選択します。[範囲全体]では、フィルの範囲全体を選択します。[フィルの方法]および[連続データ]フィールドでは、フィルの方法を変更します。 </p> <p> 範囲の開始位置として「Sheet1!A1」を、範囲全体として「Sheet1!A1:C2」を選択し、フィルの方法として「オートフィル」を、連続データでは「列」を選択します。この状態で[オートフィル]ボタンをクリックし、シート上でセルのフィルがどのように行われるかを確認します。 </p> <div class="option-row"> <label>範囲の開始位置</label> <div id="startRange" spellcheck="false" style="display:inline-block;border: 1px solid #808080;width:134px;vertical-align: middle;"> </div> </div> <div class="option-row"> <label>範囲全体</label> <div id="wholeRange" spellcheck="false" style="display:inline-block;border: 1px solid #808080;width:134px;vertical-align: middle;"> </div> </div> <div class="option-row"> <label>フィルの方法</label> <select id="fillMethods"> <option value='0' selected>fillAuto</option> <option value='1'>fillAutobyDirection</option> <option value='2'>fillLinear</option> <option value='3'>fillGrowth</option> <option value='4'>fillDate</option> </select> </div> <div class="option-row"> <div id="fillSeriesSet"> <label>FillSeries</label> <select id="fillSeries"> <option value='0' selected>Column</option> <option value='1'>Row</option> </select> </div> <div id="fillDirectionSet"> <label>FillDirection</label> <select id="fillDirection"> <option value='0' selected>Left</option> <option value='1'>Right</option> <option value='2'>Up</option> <option value='3'>Down</option> </select> </div> </div> <div class="option-row" id="fillDateUnitSet"> <label>FillDateUnit</label> <select id="fillDateUnit"> <option value='0' selected>Day</option> <option value='1'>Weekday</option> <option value='2'>Month</option> <option value='3'>Year</option> </select> </div> <div class="option-row" id="fillStepAndStop"> <label>Step</label> <input type="text" id="step"/> <label>Stop</label> <input type="text" id="stop"/> </div> <div class="option-row"> <label></label> <input type="button" id="btnFillAuto" value="fillAuto"/> <input type="button" id="btnFillAutobyDirection" value="fillAutobyDirection"/> <input type="button" id="btnFillLinear" value="fillLinear"/> <input type="button" id="btnFillGrowth" value="fillGrowth"/> <input type="button" id="btnFillDate" value="fillDate"/> </div> </div> </div> </body> </html>
.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; margin-top: 10px; } input, select { padding: 4px 8px; } input { width: 100%; margin-top: 6px; box-sizing: border-box; } label { display:inline-block; min-width: 85px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }