代码之家  ›  专栏  ›  技术社区  ›  Redwood

是否可以在代码中生成Crystal报告的小预览或缩略图?

  •  1
  • Redwood  · 技术社区  · 17 年前

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

    1 回复  |  直到 17 年前
        1
  •  2
  •   jac    15 年前

    1. Download 并从Microsoft安装DSOFile DLL。
    2. 代码

    以下是我的代码,归结为最低限度:

      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事件中,我从报告中获取缩略图对象并将其传递给转换方法。这也适用于Office文档。

    推荐文章