找回密码
 立即注册

QQ登录

只需一步,快速开始

cgh_chen

初级会员

47

主题

182

帖子

471

积分

初级会员

积分
471

活字格认证微信认证勋章

cgh_chen
初级会员   /  发表于:2016-9-27 11:57  /   查看:6808  /  回复:13
例如: 产品名称 *

13 个回复

倒序浏览
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2016-9-27 15:47:53
沙发
这个还不支持。如果要实现就是自定义单元格
回复 使用道具 举报
cgh_chen
初级会员   /  发表于:2016-9-27 16:04:23
板凳
这样太麻烦了。 自定义如何处理?设置html代码
回复 使用道具 举报
cgh_chen
初级会员   /  发表于:2016-9-28 08:42:12
地板
请问能帮忙实现一下,这样的例子吗?谢谢!
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2016-9-28 12:40:40
5#
实现Demo需要些时间,做好之后发给您。
回复 使用道具 举报
cgh_chen
初级会员   /  发表于:2016-9-28 13:30:40
6#
谢谢!非常感谢
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2016-9-29 09:09:20
7#
Demo中 * 是垂直居中的,如果需要调整位置修改 fillText 参数就好了
  1.         $(document).ready(function () {
  2.             var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"));
  3.             initSpread(spread);
  4.         });
  5.         //Custom Cell Type
  6.         function RightStartCellType() {
  7.         }
  8.         RightStartCellType.prototype = new GcSpread.Sheets.TextCellType();
  9.         RightStartCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  10.             GcSpread.Sheets.TextCellType.prototype.paint.call(this, ctx, value, x, y, w, h, style, options);
  11.             if (!ctx) {
  12.                 return;
  13.             }

  14.             ctx.save();
  15.             // draw inside the cell's boundary
  16.             ctx.rect(x, y, w, h);
  17.             ctx.clip();

  18.             ctx.font = style.font;
  19.             ctx.fillStyle = "red";

  20.             ctx.textAlign="start";
  21.             ctx.textBaseline="middle";
  22.             ctx.fillText(" *", x + ctx.measureText(value).width, y + h / 2);

  23.             ctx.restore();
  24.         };
  25.       
  26.         function initSpread(spread) {
  27.             var sheet = spread.getSheet(0);
  28.             sheet.isPaintSuspended(true);
  29.             sheet.setColumnWidth(1, 270);
  30.             var cell = sheet.getCell(1,1);
  31.             cell.cellType(new RightStartCellType());
  32.             cell.value("item1");
  33.       
  34.             sheet.isPaintSuspended(false);
  35.         };
复制代码
回复 使用道具 举报
cgh_chen
初级会员   /  发表于:2016-9-29 09:25:20
8#
谢谢
回复 使用道具 举报
cgh_chen
初级会员   /  发表于:2016-9-29 09:27:02
9#
能不能自动适应,原来的,左右对齐样式。
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2016-9-29 10:37:21
10#
本帖最后由 dexteryao 于 2016-9-29 10:49 编辑

垂直的对齐需要根据字体大小调整,比较麻烦,如果要改最好根据您的设置直接hard code吧。

  1.              RightStartCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
  2.             if (!ctx) {
  3.                 return;
  4.             }
  5.             GcSpread.Sheets.TextCellType.prototype.paint.call(this, ctx, "", x, y, w, h, style, options);
  6.             ctx.font = style.font;
  7.             var star = "* ";
  8.             var textWidth = ctx.measureText(value).width;
  9.             var starWidth = ctx.measureText(star).width;
  10.             
  11.             var hAlign = style.hAlign



  12.             ctx.save();
  13.             // draw inside the cell's boundary
  14.             ctx.rect(x, y, w, h);
  15.             ctx.clip();

  16.             ctx.textAlign="start";
  17.             ctx.textBaseline="middle";

  18.             if(hAlign === 1){
  19.                 // center
  20.                 ctx.fillText(value, x + w / 2 - textWidth / 2, y + h / 2);

  21.                 ctx.fillStyle = "red";
  22.                 ctx.fillText(star, x + w / 2 + textWidth / 2, y + h / 2);
  23.             }
  24.             else if(hAlign === 2){
  25.                 // right
  26.                 ctx.fillText(value, x + w - textWidth - starWidth, y + h / 2);
  27.                 ctx.fillStyle = "red";
  28.                 ctx.fillText(star, x + w - starWidth, y + h / 2);
  29.             }
  30.             else{
  31.                 ctx.fillText(text, x, y + h / 2);
  32.                 ctx.fillText(star, x + textWidth, y + h / 2);
  33.             }
  34.             ctx.restore();
  35.         };
  36.         };
复制代码
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部