我正在使用 Crystal 在我的项目中显示报告,并且当用户从我的 UI 中选择要显示的报告时,我希望能够向用户显示报告的小预览或缩略图。有什么方法可以从代码动态生成这些缩略图吗?

用户可以选择通过在报告文件夹中添加或删除报告来添加或删除报告,因此仅手动制作所有缩略图并不是真正的选择。

有帮助吗?

解决方案

我使用 DSOFile 对象获取报告内的缩略图,然后使用 AxHost 将返回的对象转换为我可以显示的图像。这不是我想要的解决方案,但 DSOFile 是可自由分发的,所以我想这会起作用,直到我找到更好的东西。

  1. 下载 并安装 Microsoft 的 DSOFile DLL。
  2. 添加对 **DSO OLE 文档属性阅读器 2.1 的引用
  3. 代码

这是我的代码,简化为最低限度:

  namespace Ibs.Ui.OrderPrint
  {
    public partial class OrderPrintEdit
    {
       public OrderPrintEdit()
       {
        InitializeComponent();
       }

       #region -- reports_SelectedIndexChanged(sender, e) Event Handler --
       private void reports_SelectedIndexChanged(object sender, EventArgs e)
       {
           try
           {
               DSOFile.OleDocumentPropertiesClass oleDocumentPropertiesClass = new DSOFile.OleDocumentPropertiesClass();
               DirectoryInfo reportDirectory = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Reports");
               oleDocumentPropertiesClass.Open(reportDirectory + "\\" + reports.Text,true,DSOFile.dsoFileOpenOptions.dsoOptionDontAutoCreate);
               Object thumbnail = oleDocumentPropertiesClass.SummaryProperties.Thumbnail;
               if (thumbnail != null)
               {
                   reportThumbnail.BackgroundImage = IPictureDispHost.GetPictureFromIPicture(thumbnail);
               }
               else
               {
                   reportThumbnail.BackgroundImage = null;
               }
               oleDocumentPropertiesClass.Close(false);
           }
           catch (Exception ex)
           {
           }
       }
       #endregion
   }

   internal sealed class IPictureDispHost : AxHost
   {
       private IPictureDispHost() : base("{63109182-966B-4e3c-A8B2-8BC4A88D221C}")
       {
       }
       /// <summary>
       /// Convert the dispatch interface into an image object.
       /// </summary>
       /// <param name="picture">The picture interface</param>
       /// <returns>An image instance.</returns>
       public new static Image GetPictureFromIPicture(object picture)
       {
           return AxHost.GetPictureFromIPicture(picture);
       }
   }

}

我正在表单加载上用报告名称填充组合框。在 SelectedIndexChanged 事件中,我从报告中获取 Thumbnail 对象并将其传递给转换方法。这也适用于 Office 文档。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top