爬了下demo,https://demo.grapecity.com.cn/spreadjs/SpreadJSTutorial/features/cells/formatter/format-string/purejs
基于大佬的方案,给你个高端玩法,这就跟格式化的用例一毛一样,不需要再搞个隐藏单元格干啥了。
拿走不谢
- var spread = new GC.Spread.Sheets.Workbook("ss");
- var sheet = spread.getActiveSheet();
- sheet.setColumnWidth(0, 300);
- sheet.getCell(0, 0).value(1234.456).formatter('=IF(TRIM(@)="","",IF(@=0,"","人民币"&IF(@<0,"负",)&IF(INT(@),TEXT(INT(ABS(@)),"[DBNum2]")&"元",)&IF(INT(ABS(@)*10)-INT(ABS(@))*10,TEXT(INT(ABS(@)*10)-INT(ABS(@))*10,"[DBNum2]")&"角",IF(INT(ABS(@))=ABS(@),,IF(ABS(@)<0.1,,"零")))&IF(ROUND(ABS(@)*100-INT(ABS(@)*10)*10,),TEXT(ROUND(ABS(@)*100-INT(ABS(@)*10)*10,),"[DBNum2]")&"分","整")))')
复制代码
缺点:Excel不支持这个高端的活计 |