Evenimente
Campionatele Mondiale Power BI DataViz
14 feb., 16 - 31 mar., 16
Cu 4 șanse de a intra, ai putea câștiga un pachet de conferință și ai putea ajunge la Marea Finală LIVE din Las Vegas
Aflați mai multeAcest browser nu mai este acceptat.
Faceți upgrade la Microsoft Edge pentru a profita de cele mai noi funcții, actualizări de securitate și asistență tehnică.
The file download API lets users download data from a custom visual into a file on their storage device. Downloading a visual requires user consent and admin permission provided in the admin global switch. This setting is separate from and not affected by download restrictions applied in your organization's export and sharing tenant settings.
Notă
The file download API has three methods:
exportVisualsContent
is available from API version 4.5status
is available from API version 4.6.exportVisualsContentExtended
is available from API version 5.3.apiVersion
in the pbiviz.json file.Use the file download API to export to files of the following types:
Before the download begins, a window appears asking to confirm that the visual is from a trusted source.
To use the file download API, add a declaration to the privileges array in visual capabilities.
The file download API has three methods:
exportVisualsContent
: available from API version 4.5exportVisualsContentExtended
: available from API version 5.3.The difference between the two methods is the return value.
The status method returns the status of the file download API:
The exportVisualsContent
method has four parameters:
fileType
parameter should be base64
This method returns a promise that will be resolved for a Boolean value.
The exportVisualsContentExtended
method also has four parameters:
fileType
parameter should be base64
This method returns a promise, which will be resolved with a result of type ExportContentResultInfo
that contains the following parameters:
Here's an example of how to download the content of a custom visual into an excel file and a text file.
import IDownloadService = powerbi.extensibility.IDownloadService;
...
export class Visual implements IVisual {
...
private downloadService: IDownloadService;
...
constructor(options: VisualConstructorOptions) {
this.downloadService = options.host.downloadService;
...
const downloadBtn: HTMLElement = document.createElement("button");
downloadBtn.onclick = () => {
let contentXlsx: string = ...;//content in base64
let contentTxt: string = ...;
this.downloadService.exportVisualsContent(contentTxt, "mytxt.txt", "txt", "txt file").then((result) => {
if (result) {
//do something
}
}).catch(() => {
//handle error
});
this.downloadService.exportVisualsContent(contentXlsx, "myfile.xlsx", "base64", "xlsx file").then((result) => {
if (result) {
//do something
}
}).catch(() => {
//handle error
});
this.downloadService.exportVisualsContentExtended(contentXlsx, "myfile.xlsx", "base64", "xlsx file").then((result) => {
if (result.downloadCompleted) {
//do something
console.log(result.fileName);
}
}).catch(() => {
//handle error
});
};
// if you are using API version > 4.6.0
downloadBtn.onclick = async () => {
try {
const status: powerbi.PrivilegeStatus = await this.downloadService.exportStatus();
if (status === powerbi.PrivilegeStatus.Allowed) {
const result = await this.downloadService.exportVisualsContent('aaaaa','a.txt', 'text/plain', 'aa');
// handle result
} else {
// handle if the API is not allowed
}
} catch (err) {
//handle error
}
}
}
}
Evenimente
Campionatele Mondiale Power BI DataViz
14 feb., 16 - 31 mar., 16
Cu 4 șanse de a intra, ai putea câștiga un pachet de conferință și ai putea ajunge la Marea Finală LIVE din Las Vegas
Aflați mai multe