本篇文章中将阐述如何使用快捷键,从 Excel 中复制图片到 Spread 中。Spread 表格控件在打开含有图片的 Excel 文件时将把 图片作为 Shape 插入到 Spread 表单中。

首先,需要添加 Spread PreviewKeyDown 事件来监听 Ctrl + V 粘贴事件:

 1: public Form1()
 2: {
 3:     InitializeComponent();
 4:     this.fpSpread1.PreviewKeyDown +=
 5:     new PreviewKeyDownEventHandler(fpSpread1_PreviewKeyDown);
 6: }

 

然后,在事件中获取剪切板中数据转换成图片:

 1:  Bitmap bitmap = Clipboard.GetData(DataFormats.Bitmap) as Bitmap;

最后,把图片转换为 Shape 的背景图:

 1: FarPoint.Win.Spread.DrawingSpace.RectangleShape rShape =
 2:  new FarPoint.Win.Spread.DrawingSpace.RectangleShape();
 3: rShape.Name = "myRect1";
 4: rShape.Top = 20;
 5: rShape.Left = 60;
 6: rShape.BackColor = Color.Blue;
 7: rShape.Width = 700;
 8: rShape.Height = 500;
 9: rShape.BackgroundImage = new FarPoint.Win.Picture(bitmap);
 10:  
 11: this.fpSpread1.ActiveSheet.AddShape(rShape);

 

效果图:

Demo8

Demo 下载:编辑环境 VS2010 && Spread for Winforms 7.0 && C# 点击下载