彩票走势图

Aspose.Cells 获取Excel中插入的对象

原创|其它|编辑:郝浩|2012-10-16 15:31:59.000|阅读 1011 次

概述:此demo只是讲出使用Aspose.Cells 获取Excel插入附件的原理,代码较简单。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

引入using Aspose.Cells;

(Aspose.Cells下载地址//capbkgr.cn/zh-CN/product/563/download.aspx)

此demo只是讲出取Excel插入附件的原理,代码较简单

private void AsponseTest()
        {
            Workbook awork = new Workbook(textBox1.Text);
            Worksheet asheet = awork.Worksheets[0];


            Workbook awork2 = new Workbook();
            Worksheet asheet2 = awork2.Worksheets[0];
          
            try
            {
                byte[] imageData = null;
                byte[] objectData = null;
                string sourceFullName = "";
                int upperLeftRow = 0;
                int upperLeftColumn = 0;
                int height = 0;
                int width = 0;
                bool displayAsIcon = false;
                Aspose.Cells.Drawing.OleFileType fileType = Aspose.Cells.Drawing.OleFileType.Xls;
                string progID = "";
//循环的去除插入的对象
                foreach (Aspose.Cells.Drawing.OleObject item in asheet.OleObjects)
                {
                    
                    //获取对象属性,为生成新的Excel插入对象使用
                    imageData = item.ImageData;   //对象图标
                    objectData = item.ObjectData;   //对象内同
                    sourceFullName = item.SourceFullName;
                    upperLeftRow = item.UpperLeftRow;
                    upperLeftColumn = item.UpperLeftColumn;
                    height = item.Height;
                    width = item.Width;
                    displayAsIcon = item.DisplayAsIcon;
                    fileType = item.FileType;
                    progID = item.ProgID;
                    asheet2.OleObjects.Add(upperLeftRow, upperLeftColumn, height, width, imageData);
                    
                    //此功能是读取出一个图片,并另存为
                    MemoryStream outputImage = new MemoryStream(imageData, 0, (int)imageData.Length);
                    Image returnImage = Image.FromStream(outputImage);
                    pictureBox1.Image = returnImage;
                    File.WriteAllBytes(@"C:\Users\ZhangYu\Desktop\2.txt", objectData);
                }

                //生成新的Excel,插入附件,此方法暂时只是举例插入一个对象,若需要插入多个对象,则看情况改逻辑就可以
                foreach (Aspose.Cells.Drawing.OleObject item in asheet2.OleObjects)
                {
                    item.ObjectData = objectData;
                    item.SourceFullName = sourceFullName;
                    item.DisplayAsIcon = displayAsIcon;
                    item.FileType = fileType;
                    item.SetNativeSourceFullName(sourceFullName);
                    item.ProgID = progID;
                }
                int count = asheet.OleObjects.Count;
                awork2.Save(targetPath);

            }
            catch (Exception ex)
            {


            } 

标签:Java.NET文档管理Excel

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn

文章转载自:KeyRainie的专栏-CSDN

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP