【问题标题】:How to format data in webix toExcel()?如何在 webix toExcel() 中格式化数据?
【发布时间】:2016-11-30 09:02:30
【问题描述】:

有没有办法设置导出到 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

【问题讨论】:

    标签: javascript datatable export export-to-excel webix


    【解决方案1】:

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

    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
    });
    

    请检查sn-p here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-03
      • 2021-11-25
      相关资源
      最近更新 更多