2009-02-24 45 views
1

我正在使用Crystal在我的項目中顯示報告,並且希望能夠在用戶選擇要從我的UI中顯示的報告時向用戶顯示報告的小預覽或縮略圖圖像。有沒有什麼辦法從代碼動態生成這些縮略圖?是否有可能在代碼中生成Crystal報表的小預覽或縮略圖圖像?

用戶可以通過在報告文件夾中添加或刪除報告來添加或刪除報告,因此只需手動製作所有縮略圖圖像並不是一種真正的選擇。

回答

2

我用DSOFile對象獲取報表內的縮略圖,然後使用AxHost將返回的對象轉換爲我可以顯示的圖像。這不是我想要的解決方案,但DSOFile可以自由分發,所以我想這會起作用,直到我找到更好的東西。

  1. Download並從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文檔。

+0

我還沒有嘗試過這個,但是如果我們決定再次實施這個,這絕對是我要開始的地方。 – 2010-07-27 22:45:49