在 Power BI 工作区集合中保存报表Save reports in Power BI Workspace Collections

了解如何在 Power BI 工作区集合中保存报表。Learn how to save reports within Power BI Workspace Collections. 保存报表需要有适当的权限才能成功执行。Saving reports requires proper permissions in order to work successfully.

Important

Power BI 工作区集合已弃用,到 2018 年 6 月 或合同指示时可用。Power BI Workspace Collections is deprecated and is available until June 2018 or when your contract indicates. 建议你规划到 Power BI Embedded 的迁移以避免应用程序中断。You are encouraged to plan your migration to Power BI Embedded to avoid interruption in your application. 有关如何将数据迁移到 Power BI Embedded 的信息,请参阅如何将 Power BI 工作区集合内容迁移到 Power BI EmbeddedFor information on how to migrate your data to Power BI Embedded, see How to migrate Power BI Workspace Collections content to Power BI Embedded.

在 Power BI 工作区集合中,可编辑和保存现有报表。Within Power BI Workspace Collections, you can edit existing reports and save them. 还可以创建一个新报表,并将它另存为新报表来创建另一个报表。You can also create a new report and save as a new report to create one.

若要保存报表,首先需要为特定的报表创建具有适当范围的令牌:In order to save a report, you first need to create a token for the specific report with the right scopes:

  • 若要启用“保存”,需要 Report.ReadWrite 范围To enable save Report.ReadWrite scope is required
  • 若要启用“另存为”,需要 Report.Read 和 Workspace.Report.Copy 范围To enable save as, Report.Read and Workspace.Report.Copy scopes are required
  • 若要启用“保存”和“另存为”,需要 Report.ReadWrite 和 Workspace.Report.CopyTo enable save and save as, Report.ReadWrite and Workspace.Report.Copy are required

若要在文件菜单中相应地启用“保存”/“另存为”按钮,需要在嵌入报表时,在 Embed 配置中提供适当的权限:Respectively in order to enable the right save/save as buttons in file menu you need to provide the right permission in the Embed configuration when you embed the report:

  • models.Permissions.ReadWritemodels.Permissions.ReadWrite
  • models.Permissions.Copymodels.Permissions.Copy
  • models.Permissions.Allmodels.Permissions.All

Note

访问令牌也需要适当的范围。Your access token also needs the appropriate scopes. 有关详细信息,请参阅范围For more information, see Scopes.

嵌入处于编辑模式的报表Embed report in edit mode

假设用户要在应用中嵌入一个处于编辑模式的报表,为此,只需在 Embed 配置中传递适当的属性,并调用 powerbi.embed()。Let's say you want to Embed a report in edit mode inside your app, to do so just pass the right properties in Embed configuration and call powerbi.embed(). 提供权限和 viewMode 才能在编辑模式下看到“保存”和“另存为”按钮。Supply permissions and a viewMode in order to see the save and save as buttons when in edit mode. 有关详细信息,请参阅 Embed 配置详细信息For more information, see Embed configuration details.

例如,在 JavaScript 中:For example, in JavaScript:

   <div id="reportContainer"></div>

    <script>
    // Get models. Models, it contains enums that can be used.
    var models = window['powerbi-client'].models;

    // Embed configuration used to describe the what and how to embed.
    // This object is used when calling powerbi.embed.
    // This also includes settings and options such as filters.
    // You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
    var config= {
        type: 'report',
        accessToken: 'eyJ0eXAiO...Qron7qYpY9MI',
        embedUrl: 'https://embedded.powerbi.cn/appTokenReportEmbed',
        id:  '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
        permissions: models.Permissions.All /*both save & save as buttons will be visible*/,
        viewMode: models.ViewMode.Edit,
        settings: {
            filterPaneEnabled: true,
            navContentPaneEnabled: true
        }
    };

    // Get a reference to the embedded report HTML element
    var reportContainer = $('#reportContainer')[0];

    // Embed the report and display it within the div container.
    var report = powerbi.embed(reportContainer, config);
    </script>    

现在,会在应用中嵌入一个处于编辑模式的报表。Now a report is embedded in your app in edit mode.

保存报表Save report

使用适当的令牌和权限嵌入处于编辑模式的报表后,可以通过文件菜单或 JavaScript 保存该报表:After Embedding the report in edit mode with the right token and permissions, you can save the report from the file menu or from javascript:

 // Get a reference to the embedded report.
    report = powerbi.get(reportContainer);

 // Save report
    report.save();

另存为Save as

// Get a reference to the embedded report.
    report = powerbi.get(reportContainer);
    
    var saveAsParameters = {
        name: "newReport"
    };

    // SaveAs report
    report.saveAs(saveAsParameters);

Important

只有在调用“另存为”之后,才能创建新报表。Only after save as is a new report created. 保存后,画布仍显示处于编辑模式的旧报表,而不是新报表。After the save, the canvas is still showing the old report in edit mode and not the new report. 嵌入已创建的新报表。Embed the new report that was created. 嵌入新报表需要获取新的访问令牌,因为令牌是针对每个报表创建的。Embedding the new report requires a new access token as they are created per report.

然后,需要在执行“另存为”操作后加载新报表。You will then need to load the new report after a save as. 加载新报表类似于嵌入任何报表。Loading the new report is similar to embedding any report.

<div id="reportContainer"></div>
<script>  
var embedConfiguration = {
        accessToken: 'eyJ0eXAiO...Qron7qYpY9MJ',
        embedUrl: 'https://embedded.powerbi.cn/appTokenReportEmbed',
        reportId: '5dac7a4a-4452-46b3-99f6-a25915e0fe54',
    };
    
    // Grab the reference to the div HTML element that will host the report
    var reportContainer = $('#reportContainer')[0];

    // Embed report
    var report = powerbi.embed(reportContainer, embedConfiguration);
</script>    

另请参阅See also

示例入门Get started with sample
嵌入报表Embed a report
从数据集创建新报表Create a new report from a dataset
在 Power BI 工作区集合中进行身份验证和授权Authenticating and authorizing in Power BI Workspace Collections
Power BI DesktopPower BI Desktop
JavaScript 嵌入示例JavaScript Embed Sample

有更多问题?More questions? 试用 Power BI 社区Try the Power BI Community