Spread for Winforms 表格控件:如何从 Excel 中复制图片

发布时间:2013/09/21 00:09 发布者:iceman

返回博客中心

本篇文章中将阐述如何使用快捷键,从 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# 点击下载


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网