[示例代码]显示和保存Stimulsoft Reports.WinRT报表

作者:hesj    来源:慧都控件网    浏览:Loading...      日期:2013-03-18

Stimulsoft Reports.WinRT中的ViewerRT用于在WinRT中显示报表、缩放、保存、打印报表的控件。本文将展示如何加载和保存报表的代码。

显示报表

添加以下代码便可以显示已经渲染好的报表(*.mdc, *.mdz, *.mdx)。

XAML文件:

<Page x:Class="Demo.RT.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewerRT="using:Stimulsoft.Report.Viewer.RT">
<viewerRT:StiViewerControl x:Name="viewerControl"/>
</Page>

CS文件:

namespace Demo.RT
{
public sealed partial class BlankPage : Page
    {
        #region Handlers
        async private void BlankPage_Loaded(object sender, RoutedEventArgs
e)
        {
            StorageFolder folder = Windows.Storage.KnownFolders.
DocumentsLibrary;
            StorageFile storageFile = await folder.GetFileAsync(
"SimpleList.mdc");
            StiReport report = new StiReport();
            await report.LoadDocumentAsync(storageFile);
            viewerControl.Report = report;
        }
        #endregion
        public BlankPage()
        {
            this.InitializeComponent();
            this.Loaded += BlankPage_Loaded;
        }
    }
}

以下代码用于显示报表模板,即还未渲染的报表(*.mrt, *.mrz, *.mrx)。

XAML文件:

<Page x:Class="Demo.RT.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewerRT="using:Stimulsoft.Report.Viewer.RT">
<viewerRT:StiViewerControl x:Name="viewerControl"/>
</Page>

CS文件:

namespace Demo.RT
{
public sealed partial class BlankPage : Page
{
#region Handlers
async private void BlankPage_Loaded(object sender,
RoutedEventArgs e)
{
StorageFolder folder = Windows.Storage.KnownFolders.
DocumentsLibrary;
StorageFile storageFile = await folder.GetFileAsync
("SimpleList.mrt");
StiReport report = new StiReport();
await report.LoadAsync(storageFile);
await report.RenderAsync();
viewerControl.Report = report;
}
#endregion
public BlankPage()
{
this.InitializeComponent();
this.Loaded += BlankPage_Loaded;
}
}
}

接下来可以通过点击“打开”按钮打开已渲染的报表。

Stimulsoft Reports.WinRT显示和保存报表的代码示例


保存报表

下面是保存报表的代码示例。

XAML文件:

<Page x:Class="Demo.RT.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewerRT="using:Stimulsoft.Report.Viewer.RT">
<viewerRT:StiViewerControl x:Name="viewerControl"/>
</Page>

CS文件:

namespace Demo.RT
{
public sealed partial class BlankPage : Page
{
#region Handlers
async private void buttonSaveReport_Click(object sender,
RoutedEventArgs e)
         {
StiReport report = new StiReport();
StorageFolder folder = Windows.Storage.KnownFolders.
DocumentsLibrary;
StorageFile storageFile = await folder.CreateFileAsync
("Report1.mdc");
await report.SaveDocumentAsync(storageFile);
         }
#endregion
public BlankPage()
{
this.InitializeComponent();
this.Loaded += BlankPage_Loaded;
}
}
}

Tag标签:StimulsoftReports.WinRT 

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:Stimulsoft中文网 [http://www.Stimulsoft.cn/]
本文地址: http://www.Stimulsoft.cn/Resources/doc/169.html

上一篇: 报表工具Stimulsoft Reports快捷键汇总

下一篇: Stimulsoft Reports报表数据源设置方法一