如果 webdatarocks 中有配置为时间的数据,则在 Excel 中以 hh:mm:ss 格式正确导出。但是,如果我们有一个计算值,它是通过将时间值除以数值(以获得平均值)而获得的,并且这个计算值被定义为时间,那么在 web 中它会以正确的格式显示,但在导出中 - 以秒为单位。下面是来自 webdatarocks codepen 的示例,我在其中添加了新的值 AVG。在网页上显示为 00:20:00,但在 excel 中导出为 1200
"Duration": {
type: "time"
},
"Movie Name": {
type: "string"
},
"AVG": {
type: "time"
},
"Rating": {
type: "number"
},
"Genre": {
type: "string"
}
},
{
"Movie Name": "Star Wars: The Last Jedi",
"Rating": 7.2,
"Genre": "Fantasy",
"Duration": 9120
},
{
"Movie Name": "Blade Runner 2049",
"Rating": 7.2,
"Genre": "Sci-Fi",
"Duration": 9840
},
{
"Movie Name": "Harry Potter and the Sorcerer's Stone",
"Rating": 7.6,
"Genre": "Adventure",
"Duration": 9120
},
{
"Movie Name": "Incredibles 2",
"Rating": 8.1,
"Genre": "Animation",
"Duration": 7080
},
{
"Movie Name": "Ratatouille",
"Rating": 8.0,
"Genre": "Comedy",
"Duration": 6660
},
{
"Movie Name": "Scott Pilgrim vs. the World",
"Rating": 7.5,
"Genre": "Romance",
"Duration": 6720
}
];
var pivot = new WebDataRocks({
container: "wdr-component",
toolbar: true,
report: {
dataSource: {
data: JSONData
},
"slice": {
"rows": [
{
"uniqueName": "Movie Name"
}
],
"columns": [
{
"uniqueName": "Genre"
},
{
"uniqueName": "Duration"
},
{
"uniqueName": "Measures"
}
],
"measures": [
{
"uniqueName": "Rating",
"aggregation": "sum"
},
{
"uniqueName": "AVG",
"formula": "sum(\"Duration\") / sum(\"Rating\")",
"caption": "Avg"
},
],
"expands": {
"columns": [
{
"tuple": [
"Genre.Adventure"
]
},
{
"tuple": [
"Genre.Animation"
]
},
{
"tuple": [
"Genre.Comedy"
]
},
{
"tuple": [
"Genre.Fantasy"
]
}
]
}
}
}
});