全シートの背景色または背景イメージを設定するには、backColorまたはbackgroundImageを使用します。背景色と背景イメージの両方を設定した場合は、背景イメージが表示されます。
SpreadJSでは、背景イメージのレイアウトをbackgroundImageLayoutを使用して制御できます。イメージのレイアウトには、以下のタイプがあります。
stretch:
背景画像を領域全体に引き伸ばすことを指定します。
center:
背景画像を領域の中央に表示することを指定します。
zoom:
画像のアスペクト比を維持したまま背景画像を領域に表示することを指定します。
none:
領域の左上隅から元のサイズで背景画像を表示することを指定します。
grayAreaBackColorを使用すると、灰色領域(シートの最大行や最大列を超えてスクロールしたときの、セルがない領域)の色を設定することもできます。
window.onload = function() {
var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 1 });
initSpread(spread);
};
function initSpread(spread) {
var spreadNS = GC.Spread.Sheets;
var sheet = spread.getSheet(0);
var pictureUrl = '';
spread.suspendPaint();
sheet.setRowCount(15);
sheet.setColumnCount(20);
spread.options.backColor = 'white';
spread.options.grayAreaBackColor = 'gray';
spread.options.backgroundImageLayout = spreadNS.ImageLayout.stretch;
spread.options.backgroundImage = '$DEMOROOT$/spread/source/images/backImage.png';
spread.resumePaint();
_getElementById('layout').addEventListener('change',function() {
var layout = parseInt(document.getElementById('layout').value);
spread.options.backgroundImageLayout = layout;
});
_getElementById('setGrayAreaBackColor').addEventListener('click', function() {
var color = document.getElementById('grayAreaBackColor').value;
spread.options.grayAreaBackColor = color;
});
_getElementById('setSpreadBackColor').addEventListener('click', function() {
var color = document.getElementById('spreadBackColor').value;
spread.options.backColor = color;
});
_getElementById('file_input').addEventListener('change', function() {
var file = this.files[0];
if (!/image\/\w+/.test(file.type)) {
alert('The file muse be image!');
return false;
}
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e) {
pictureUrl = this.result;
};
});
_getElementById('setSpreadBackgroundImage').addEventListener('click', function() {
spread.options.backgroundImage = pictureUrl;
});
_getElementById('delSpreadBackgroundImage').addEventListener('click', function() {
spread.options.backgroundImage = '';
});
}
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">
<div class="option-row">
<label >色の名前を入力し、Spreadの灰色領域の色を設定します。</label>
</div>
<div class="option-row">
<input type="text" id="grayAreaBackColor"/>
<input type="button" id="setGrayAreaBackColor" value="灰色領域の色を設定"/>
</div>
<div class="option-row">
<label >色の名前を入力し、Spreadの背景色を設定します。</label>
<label class="note">注:この設定変更の効果を確認するには、下部の背景画像を削除してください。</label>
</div>
<div class="option-row">
<input type="text" id="spreadBackColor"/>
<input type="button" id="setSpreadBackColor" value="Spreadの背景色を設定"/>
</div>
<div class="option-row">
<label >画像:</label>
<input type="file" name="image" id="file_input" />
</div>
<div class="option-row">
<label >Spread背景画像のレイアウト:</label>
<select id="layout" >
<option value="0" selected="selected">Stretch</option>
<option value="1">Center</option>
<option value="2">Zoom</option>
<option value="3">None</option>
</select>
</div>
<div class="option-row">
<input type="button" id="setSpreadBackgroundImage" value="設定" class="narrow-button" />
<input type="button" id="delSpreadBackgroundImage" value="背景画像を削除" />
</div>
</div>
</div>
</body>
</html>
input[type="button"] {
width: 180px;
}
input[type="text"] {
padding: 4px;
margin-top: 4px;
width: 100%;
box-sizing: border-box;
}
label {
display: inline-block;
margin-bottom: 6px;
}
.note{
margin-top: 0px;
}
.colorLabel {
background-color: lavender;
}
.wide-label {
width: 260px;
}
input.narrow-button, .narrow-label {
width: 74px;
}
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 300px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 300px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row:nth-child(1){
padding-bottom: 0px;
}
.option-row:nth-child(2){
margin-top: 0px;
padding-top: 0px;
}
.option-row:nth-child(3){
padding-bottom: 0px;
}
.option-row:nth-child(4){
margin-top: 0px;
padding-top: 0px;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input {
padding: 4px 6px;
}
input[type=button] {
margin-top: 6px;
display: block;
}
hr {
border-color: #fff;
opacity: .2;
margin-top: 20px;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}