还有没有人知道一个.NET C#库中的WinForms和Microsoft服务报告显示CGM文件/ CrystalReports,使其打印呢?
Does any one knows a .NET C# library for displaying CGM files in WinForms and Microsoft Service Reports/CrystalReports so that it is printable as well?
这也将是非常有帮助的,如果它也可以将文件转换为如JPEG,GIF,PNG等。
It would also be extremely helpful if it is also be able to convert the file to a web-frendly graphics format like jpeg, gif, png etc..
这可能是一个重复的问题,从 .NET库CGM文件转换但OP没有标注答案,也不是建议的解决方案.NET兼容。
This is likely a repeated question from .NET Library for CGM File Conversion but that OP did not mark an answer nor were the suggested solutions .NET compatible.
所以,我只是重新尝试我的运气。感谢您的帮助。
So I am just trying my luck again. Thanks for helping.
我只是想和SO分享这个临时的黑客。我还需要一个正确的库如果可能的话(幸得大家谁使.NET的Excel教程在网上提供):
I just want to share this temporary hack with SO. I still need a proper library if possible (Credit goes to everyone who makes .NET excel tutorials available online):
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();
}
}
}
}