找回密码
 立即注册

QQ登录

只需一步,快速开始

iceman

社区贡献组

270

主题

1万

帖子

1万

积分

社区贡献组

积分
19311

活字格认证微信认证勋章元老葡萄

iceman
社区贡献组   /  发表于:2012-3-14 15:38  /   查看:5985  /  回复:2
Spread for ASP.NET 可以在单元格中显示图片。其中用例之一就是可以使最终用户上传图片到 Spread 中。在这片文章将展示如何使最终用户动态的上传图片到 Spread 单元格中。

下面将分布讲解怎么实现该功能:

1.在 WebForm 页面上添加 Spread ,同时在添加 标准控件 Button、FileUpload。

2.在 Button 的 Click 事件中添加上传图片代码。
  1. protected void Button1_Click(object sender, EventArgs e)
  2.         {
  3.             //添加 DirectoryInfo 实例映射存储图片文件夹
  4.             DirectoryInfo imagePath= new DirectoryInfo(this.Server.MapPath("Images"));

  5.              //获取文件夹中的图片,如果存在图片删除
  6.             FileInfo[] images = imagePath.GetFiles();
  7.             if (images.Length!=0)
  8.             {
  9.                 foreach (FileInfo image in images)
  10.                 {
  11.                     image.Delete();
  12.                 }
  13.             }
  14.                
  15.             //上传文件
  16.             if (this.FileUpload1.HasFile)
  17.             {
  18.                 if (this.FileUpload1.PostedFile.ContentLength<1024000)
  19.                 {
  20.                     this.FileUpload1.SaveAs(this.Server.MapPath("Images") + "\\" + Path.GetFileName(FileUpload1.FileName));
  21.                 }
  22.                
  23.                 //设置 ImageCellType
  24.                 FarPoint.Web.Spread.ImageCellType imageCellType = new FarPoint.Web.Spread.ImageCellType();
  25.                 imageCellType.ImageUrl = "Images/" + this.FileUpload1.FileName;
  26.                 this.FpSpread1.Sheets[0].Cells[0, 0].CellType = imageCellType;
  27.             }
  28.         }
复制代码
3.图片展示

上传前图片:

png

png

点击浏览按钮选择图片

png

png

上传图片到 Spread 单元格中

png

png

4.Demo 下载:
测试环境:VS 2010 && Spread for ASP.NET 5.0
UploadImageToCell.zip (2.95 MB, 下载次数: 318)

2 个回复

倒序浏览
kang10111
新手上路   /  发表于:2012-3-26 09:40:00
沙发
不错啊
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2012-3-26 09:51:00
板凳

回复 2# kang10111 的帖子

感谢支持~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部