ピクチャ

レイアウトや枠線など、Pictureフローティングオブジェクトのさまざまな属性をカスタマイズできます。

<p>ピクチャの画像を設定または変更するには、<strong>src</strong>メソッドを使用します。ピクチャのsrcには、base64画像を使用できます。</p> <pre><code class="hljs js language-js"> picture.src(<span class="hljs-string">'images/spreadLogo.png'</span>); <span class="hljs-keyword">var</span> originalWidth = picture.getOriginalWidth(); <span class="hljs-keyword">var</span> originalHeight = picture.getOriginalHeight(); picture.width(originalWidth); picture.height(originalHeight); </code></pre> <p>ピクチャのレイアウトを変更するには、<strong>pictureStretch</strong>メソッドを使用します。ピクチャの伸縮方法は、<strong>ImageLayout</strong>列挙型で定義します。画像の元のサイズを取得するには、<strong>getOriginalWidth</strong>および<strong>getOriginalHeight</strong>メソッドを使用します。</p> <p>ピクチャの枠線を追加できます。この枠線は、DOMの枠線設定として定義されます。次に、例を示します。</p> <pre><code class="hljs js language-js"> picture.borderStyle(<span class="hljs-string">'solid'</span>); picture.borderWidth(<span class="hljs-number">2</span>); picture.borderColor(<span class="hljs-string">'red'</span>); picture.borderRadius(<span class="hljs-number">4</span>); </code></pre> <p>ピクチャの一部が透明な場合は、背景領域の色を設定することもできます。ピクチャの背景色を取得または設定するには、<strong>backColor</strong>メソッドを使用します。次に、例を示します。</p> <pre><code class="hljs js language-js"> picture.backColor(<span class="hljs-string">'green'</span>); </code></pre>
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">Spreadコンポーネント内のピクチャを選択し、以下のオプションを使用して変更を加えます。</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:lavender; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }