上传图片到 Spread 单元格中

发布时间:2012/11/14 00:11 发布者:葡萄城产品团队

返回博客中心

Spread for ASP.NET 可以在单元格中显示图片。其中用例之一就是可以使最终用户上传图片到 Spread 中。在这片文章将展示如何使最终用户动态的上传图片到 Spread 单元格中。

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

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)

关于葡萄城

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

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