我试图将报表的单元格内容复制到我的Microsoft PowerBI应用程序中的剪贴板中。
在我的配置中,我有这个:
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true,
extensions: [
{
command: {
name: "CopyToClipBoard",
title: "Copy to Clipboard",
extend:
{
visualContextMenu: {
title: "Copy"
}
}
}
}
]
}
这会显示一个右键菜单,其中我看到复制作为我的新选项。
然后我创建了收集数据的方法:
report.on("commandTriggered", function (command) {
console.log(command);
var details = command.detail;
if (details.command === "CopyToClipBoard") {
//I thought the selection was in the first DataPoint, first Identity. It's not.
var dpoints = details.dataPoints[0].identity[0].equals;
CopyData(dpoints);
}
});
function CopyData(dpoints) {
//Get the selected text and append the extra info
var newdiv = document.createElement('div');
var selection = window.getSelection();
//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';
//insert the container, fill it with the extended text, and define the new selection
document.body.appendChild(newdiv);
newdiv.innerHTML = dpoints;
selection.selectAllChildren(newdiv);
document.execCommand("copy");
window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}
问题是该命令不包含单元格中的任何元素。它仅包含数据点/标识,其中包含单元的位置或标识。
我怎样才能获得单元格文本?
答案 0 :(得分:0)
看起来像现在收集价值仍然在进行中.... https://github.com/Microsoft/PowerBI-JavaScript/wiki/Handling-Events