下面将分布讲解怎么实现该功能:
1.在 WebForm 页面上添加 Spread ,同时在添加 标准控件 Button、FileUpload。
2.在 Button 的 Click 事件中添加上传图片代码。
protected void Button1_Click(object sender, EventArgs e) { //添加 DirectoryInfo 实例映射存储图片文件夹 DirectoryInfo imagePath= new DirectoryInfo(this.Server.MapPath("Images")); //获取文件夹中的图片,如果存在图片删除 FileInfo[] images = imagePath.GetFiles(); if (images.Length!=0) { foreach (FileInfo image in images) { image.Delete(); } } //上传文件 if (this.FileUpload1.HasFile) { if (this.FileUpload1.PostedFile.ContentLength<1024000) { this.FileUpload1.SaveAs(this.Server.MapPath("Images") + "\\" + Path.GetFileName(FileUpload1.FileName)); } //设置 ImageCellType FarPoint.Web.Spread.ImageCellType imageCellType = new FarPoint.Web.Spread.ImageCellType(); imageCellType.ImageUrl = "Images/" + this.FileUpload1.FileName; this.FpSpread1.Sheets[0].Cells[0, 0].CellType = imageCellType; } } 复制代码3.图片展示
上传前图片:
点击浏览按钮选择图片
上传图片到 Spread 单元格中
4.Demo 下载:
测试环境:VS 2010 && Spread for ASP.NET 5.0
- UploadImageToCell.zip (2.95 M, 下载次数:21)