如何在 webix toExcel() 中格式化数据?

How to format data in webix toExcel()?

有什么方法可以将导出的列格式设置为 Excel?似乎它只适用于原始数据集。顺便说一句,Date 对象作为日期导出(这几乎没问题),但我想导出具有指定 format 的数据。可能吗? TIA

例如,这是带有格式化列的数据表:

    {
      view:"datatable", 
      id:"data",
      ...
      scheme:{      // converting numbers to the Date objects
        $init:function(obj){
          obj.year = new Date(obj.year.toString())
        }
      },
      columns:[
        { id:"title", fillspace:true },
        { id:"year", width:150, format:webix.Date.dateToStr("%M, %Y") },
        { id:"votes", width:150, format:webix.i18n.numberFormat  }
      ]
    },
    { view:"button", click:"{webix.toExcel($$('data'))}"}

这里是 code sample

您使用的格式属性设置了在您的列中显示的日期格式。为了在 excel 中获取自定义日期,您需要添加自定义格式,以便将日期转换为所需格式。查看解释 .

var format = webix.Date.dateToStr("%M, %Y");
webix.ui({
  width:550,
  rows:[
    { 
      //your code 
     columns:[
         // .....
        { id:"year", width:150, template: function(obj){ return format(obj.year)}},
        // ....
      ]
    }
   //your code for the button
});

请检查代码段 here