ピクチャの画像を設定または変更するには、srcメソッドを使用します。ピクチャのsrcには、base64画像を使用できます。
ピクチャのレイアウトを変更するには、pictureStretchメソッドを使用します。ピクチャの伸縮方法は、ImageLayout列挙型で定義します。画像の元のサイズを取得するには、getOriginalWidthおよびgetOriginalHeightメソッドを使用します。
ピクチャの枠線を追加できます。この枠線は、DOMの枠線設定として定義されます。次に、例を示します。
ピクチャの一部が透明な場合は、背景領域の色を設定することもできます。ピクチャの背景色を取得または設定するには、backColorメソッドを使用します。次に、例を示します。
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
initSpread(spread);
};
function initSpread(spread) {
var sheet = spread.getSheet(0);
var picture = sheet.pictures.add("f2", "$DEMOROOT$/spread/source/images/spreadLogo.png", 50, 50, 100, 100);
picture.backColor("black");
document.getElementById('pictureStretch').onchange = function (e) {
var sheet = spread.getActiveSheet();
var pictures = sheet.pictures.all();
var stretch = parseInt(e.target.value);
if (pictures) {
for (var index = 0, len = pictures.length; index < len; index++) {
var picture = pictures[index];
if (picture.isSelected()) {
picture.pictureStretch(stretch);
}
}
}
};
document.getElementById('borderStyle').onchange = function (e) {
var sheet = spread.getActiveSheet();
var pictures = sheet.pictures.all();
var borderStyle = e.target.value;
if (pictures) {
for (var index = 0, len = pictures.length; index < len; index++) {
var picture = pictures[index];
if (picture.isSelected()) {
picture.borderStyle(borderStyle);
}
}
}
};
document.getElementById('set').onclick = function () {
var sheet = spread.getActiveSheet();
var pictures = sheet.pictures.all();
var borderColor = document.getElementById('borderColor').value;
var borderWidth = parseFloat(document.getElementById('borderWidth').value);
var borderStyle = document.getElementById('borderStyle').value;
var borderRadius = parseFloat(document.getElementById('borderRadius').value);
var backColor = document.getElementById('backColor').value;
var pictureStretch = parseInt(document.getElementById('pictureStretch').value);
if (pictures) {
for (var index = 0, len = pictures.length; index < len; index++) {
var picture = pictures[index];
if (picture.isSelected()) {
picture.borderColor(borderColor);
picture.borderWidth(borderWidth);
picture.borderStyle(borderStyle);
picture.borderRadius(borderRadius);
picture.backColor(backColor);
picture.pictureStretch(pictureStretch);
}
}
}
sheet.repaint();
};
document.getElementById('resetPicture').onclick = function () {
var sheet = spread.getActiveSheet();
var pictures = sheet.pictures.all();
if (pictures) {
for (var index = 0, len = pictures.length; index < len; index++) {
var picture = pictures[index];
if (picture.isSelected()) {
var originalWidth = picture.getOriginalWidth();
var originalHeight = picture.getOriginalHeight();
if (originalWidth > 0 && originalHeight > 0) {
picture.width(originalWidth);
picture.height(originalHeight);
}
}
}
}
sheet.repaint();
};
};
<!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">
<p class="desc">スプレッドシート内のピクチャを選択し、以下のオプションを使用して変更を加えます。</p>
</div>
<div class="option-row">
<label for="borderColor">枠線の色:</label>
<input type="text" id="borderColor" />
</div>
<div class="option-row">
<label for="borderWidth">枠線の幅:</label>
<input type="text" id="borderWidth" />
</div>
<div class="option-row">
<label for="borderRadius">枠線の半径:</label>
<input type="text" id="borderRadius" />
</div>
<div class="option-row">
<label for="backColor">背景色:</label>
<input type="text" id="backColor" />
</div>
<div class="option-row">
<label>枠線のスタイル:</label>
<select id="borderStyle">
<option value="solid" selected="selected">solid</option>
<option value="dotted">dotted</option>
<option value="dashed">dashed</option>
<option value="double">double</option>
<option value="groove">groove</option>
<option value="ridge">ridge</option>
<option value="inset">inset</option>
<option value="outset">outset</option>
</select>
</div>
<div class="option-row">
<label>ピクチャの伸縮:</label>
<select id="pictureStretch">
<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="set" value="設定" />
<input type="button" id="resetPicture" value="元のサイズにリセット" />
</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: 5px;
}
select, input {
padding: 4px 6px;
box-sizing: border-box;
margin-top: 6px;
width: 100%;
}
.desc{
padding:2px 10px;
background-color:#F4F8EB;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}