Image

The Image sparkline can be used to place an image in a cell. The image can be displayed in different sizes by using display modes of image sparkline function. The source of the image can be a URL or base64 string.

You can create an image using the image function in a formula:=IMAGE(URL,mode,height,width,clipX,clipY,clipHeight,clipWidth,vAlign,hAlign) This function has the following parameters: URL: The location of the image on web or base string. mode: (optional) A number that represents the image fit mode. One of the following: Keep Scale To Fit - 1 Entire Image To Fit - 2 Origin Size To Fit - 3 Custom Size To Fit - 4 height: (optional) This is the height of image when mode is 4. width: (optional) This is the width of image when mode is 4. clipX: (optional) The X-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context. clipY: (optional) The Y-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context. clipHeight: (optional) The height of the sub-rectangle of the source image to draw into the destination context. clipWidth: (optional) The width of the sub-rectangle of the source image to draw into the destination context. vAlign: (optional) This value indicates the vertical alignment of the image. One of the following: Top - 0 Center - 1 Bottom - 2 hAlign: (optional) This value indicates the horizontal alignment of the image. One of the following: Left - 0 Center - 1 Right - 2
window.onload = () => { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); initSpread(spread); } function initSpread(spread) { spread.suspendPaint(); spread.setSheetCount(2); var sheet = spread.getSheet(0); spread.options.allowDynamicArray = true; initSheet(sheet, applyImageFormula); var sheet2 = spread.getSheet(1); initSheet(sheet2, applyImageFormatter); spread.resumePaint(); } function applyImageFormula(sheet) { for (let i = 2; i < 17; i++) { sheet.setFormula(i, 0, '=IMAGE(F' + (i + 1) + ')'); } sheet.setColumnWidth(5, 0); } function applyImageFormatter(sheet) { for (let i = 2; i < 17; i++) { sheet.getCell(i, 5).formatter('=IMAGE(@)'); } } function initSheet(sheet, fnCallback) { sheet.suspendPaint(); sheet.addSpan(0, 0, 1, 6); sheet.getCell(0, 0).value("Employees List").font("17px Arial").backColor("#E8E8E8").vAlign(GC.Spread.Sheets.VerticalAlign.center); sheet.getRange(1, 0, 1, 6).font("bold 13px Arial").vAlign(GC.Spread.Sheets.VerticalAlign.center) .setBorder(new GC.Spread.Sheets.LineBorder("black", GC.Spread.Sheets.LineStyle.thin), { bottom: true }); sheet.setArray(1, 1, data); if (fnCallback) { fnCallback.apply(this, [sheet]); } sheet.getRange(2, 4, 15, 1).formatter('dd-MM-yyyy').hAlign(GC.Spread.Sheets.HorizontalAlign.center); sheet.getRange(2, 0, 15, 6).vAlign(GC.Spread.Sheets.VerticalAlign.center); for (var i = 1; i < 5; i++) { sheet.setColumnWidth(i, 160); } for (var i = 2; i < 17; i++) { sheet.setRowHeight(i, 55); } sheet.setRowHeight(0, 30); sheet.setRowHeight(1, 30); sheet.setColumnWidth(0, 80); sheet.addSpan(2, 7, 1, 5); sheet.setText(2, 7, "You can set image according to URL or base64"); sheet.getRange(2, 7, 2, 2).vAlign(GC.Spread.Sheets.VerticalAlign.center) .hAlign(GC.Spread.Sheets.HorizontalAlign.center); sheet.addSpan(3, 7, 2, 5); sheet.setFormula(3, 7, '=IMAGE("https://www.grapecity.com/spreadjs/demos/spread/source/logo-en.ico",4,50,150)'); sheet.resumePaint(); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/en/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/image-sparkline.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" style="width:100%;height:100%"></div> </div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }