2011-01-27 60 views
3

是否有人知道用於在WinForms和Microsoft Service Reports/CrystalReports中顯示CGM文件的.NET C#庫,以便它可以打印?CGM(計算機圖形圖元文件)格式的.NET或C#庫?

這也將是非常有益的,如果還能夠將文件轉換爲JPEG一樣,GIF,PNG等網絡,員工共贏的圖形格式,它..

這可能是從.NET Library for CGM File Conversion但一個重複的問題OP沒有標記答案,也沒有提出解決方案.NET兼容。

所以,我只是再次嘗試我的運氣。感謝您的幫助。

回答

3

我只是想與SO分享這個臨時攻擊。如果可能的話,我仍然需要一個合適的庫(可以在網上獲得.NET excel教程的所有人):

using System; 
using Excel = Microsoft.Office.Interop.Excel; 
using Microsoft.Office.Core; 
using System.Drawing; 

namespace CGM 

{ 
    public class CGMConverter 
    { 
     Image _mImage; 

     public Image Image { get { return _mImage; } } 

     public CGMConverter(string cgm, float width, float height) 
     { 
      object misValue = System.Reflection.Missing.Value; 
      Excel.Application xlsApp = null; 
      Excel.Workbook xlsWorkBook = null; 
      Excel.Worksheet xlsWorkSheet = null; 

      try 
      { 
       xlsApp = new Excel.ApplicationClass(); 
       xlsWorkBook = xlsApp.Workbooks.Add(misValue); 
       xlsWorkSheet = (Excel.Worksheet)xlsWorkBook.Sheets["sheet1"]; 
       xlsWorkSheet.Shapes.AddPicture(cgm, MsoTriState.msoFalse, MsoTriState.msoTrue, 50, 50, width, height); 
       xlsWorkSheet.Shapes.Item(0).Copy(); 
       _mImage = System.Windows.Forms.Clipboard.GetImage(); 
      } 
      catch(Exception e) 
      { 
       throw (e); 
      } 
      finally 
      { 
       xlsApp.DisplayAlerts = false; 
       xlsApp.Quit(); 
       releaseObject(xlsWorkSheet); 
       releaseObject(xlsWorkBook); 
       releaseObject(xlsApp); 
      } 
     } 

     private void releaseObject(object obj) 
     { 
      try 
      { 
       System.Runtime.InteropServices.Marshal.ReleaseComObject(obj); 
       obj = null; 
      } 
      catch (Exception ex) 
      { 
       obj = null; 
      } 
      finally 
      { 
       GC.Collect(); 
      } 
     } 
    } 
}