c#chart.object从Excel作为.png低分辨率

我创build了一个excel文件,并希望将其内容导出为png或jpeg文件。

不幸的是,图像的质量是非常低的。

有针对这个的解决方法吗? 我希望一个真正的高分辨率的图片。

谢谢

我目前的代码(来自互联网):

Excel.Range xlRange = xlWorksheet5.get_Range("A1", "K30"); xlRange.CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlPicture); Excel.ChartObject chartObj; chartObj = xlWorksheet5.ChartObjects().Add(xlRange.Left, xlRange.Top, xlRange.Width, xlRange.Height); chartObj.Activate(); string path_image = path + "\\image.png"; Excel.Chart chart = chartObj.Chart; chart.Paste(); chart.Export(path_image); 

尝试这个。 你需要把[STAThread]属性放在你运行的任何线程的入口点上。

  //This first copy/paste is to convert from chart to image chartObj.CopyPicture(); xlWorksheet5.Paste(); //This image has decent resolution xlWorksheet5.Shapes.Item(xlWorksheet5.Shapes.Count).Copy(); //Save the image System.Windows.Media.Imaging.BitmapEncoder enc = new System.Windows.Media.Imaging.BmpBitmapEncoder(); enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(System.Windows.Clipboard.GetImage())); using (System.IO.MemoryStream outStream = new System.IO.MemoryStream()) { enc.Save(outStream); System.Drawing.Image pic = new System.Drawing.Bitmap(outStream); pic.Save("image.png"); }