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2kRV21Plo21Iw7j3+YemmLaXAev98NTMDrlWdp3rb55P6ygSRTjv/MnWr7dXfSSZ+0OTilV6V1VvSySJJONgqXtUDAejum3lTvJRA23r9mbFVP/MMYGzv0mQKiyQrXbr9Z9IKu3n5BkhJTxJQ6/r0/bY2OFD/Zl9GIyRJJO7z8d7hpx2J6WT5TRUmEuvzzRe7O4ff77DJIvOOThA8lhSzKwDfxks00R4Cd/+fP2kXe5cwK5007LODSidBbs7OkVO+OX/vzqbzyDRMvwCSDdy0IEAS4gAAAABJRU5ErkJggg=="
- function MyCellType() {
-
- }
- MyCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
- MyCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- //Paints a cell on the canvas.
- if (value) {
- GC.Spread.Sheets.CellTypes.Base.prototype.paint.apply(this, [ctx, value, x, y, w, h, style, options]);
- var sheet = options.sheet, row = options.row, col = options.col;
- var tag = sheet.getTag(row, col);
- if(tag && tag.img){
- ctx.drawImage(tag.img, x + w - h + 1, y + 1, h - 2, h - 2);
- }
- else{
- var img = new Image();
- img.src = iconImage;
- img.onload = function(){
- sheet.setTag(row, col, {img: img})
- sheet.repaint();
- }
- }
- }
- };
- MyCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
- if (editorContext) {
- $(editorContext).width(cellRect.width);
- $(editorContext).height(cellRect.height);
- $('img', $(editorContext)).height(cellRect.height).width(cellRect.height);
- $('span', $(editorContext)).css("font", cellStyle.font);
- }
- };
- MyCellType.prototype.createEditorElement = function(context) {
- //Creates a DOM element then returns it.
- var div = document.createElement("div");
- var $div = $(div);
- $div.attr("gcUIElement", "gcEditingInput");
- $div.css("overflow", "hidden");
- var img=$("<img src="+iconImage+" style='position: absolute;top: 0;right: 0;'/>");
- var span=$("<span style='margin: 1px'></span>");
- span.css("display", "block");
- $div.append(span);
- $div.append(img);
- return div;
- };
- MyCellType.prototype.getEditorValue = function(editorContext) {
- //Gets the editor's value.
- return $('span', $(editorContext)).text()
- };
- MyCellType.prototype.setEditorValue = function(editorContext, value) {
-
- //Sets the editor's value.
- $('span', $(editorContext)).text(value)
-
- };
- MyCellType.prototype.activateEditor = function(editorContext, cellStyle, cellRect) {
- //Activates the editor, including setting properties or attributes for the editor and binding events for the editor.
- $('img', $(editorContext)).click(function(){
- alert("message");
- })
- };
- window.onload = function () {
- var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
- var activeSheet = spread.getActiveSheet();
- activeSheet.getCell(1, 1).value("Click").cellType(new MyCellType());
- activeSheet.setColumnWidth(1, 80)
- };
-
复制代码 |