当前位置:编程学习 > C#/ASP.NET >>

apose.cell中Excel问题

InsertPicturesIntoDataTabl和GetPicturesFromExcelFile这两个函数怎么定义
// Excel文件转换为DataTable.
        public static bool ExcelFileToDataTable(string filepath, out DataTable datatable, out string error)
        {
            error = "";
            datatable = null;
            try
            {
                if (File.Exists(filepath) == false)
                {
                    error = "文件不存在";
                    datatable = null;
                    return false;
                }
                Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
                workbook.Open(filepath);
                Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
                datatable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1);
                //-------------图片处理-------------
                Aspose.Cells.Pictures pictures = worksheet.Pictures;
                if (pictures.Count > 0)
                {
                    string error2 = "";
                    if (InsertPicturesIntoDataTable(pictures, datatable, out datatable, out error2) == false)
                    {
                        error = error + error2;
                    }
                }
                return true;
            }
    
            catch (System.Exception e)
            {
                error = e.Message;
                return false;
            }

        }
            
        public static bool ExcelFileToLists(string filepath, out IList[] lists, out string error)
        {
            error = "";
            lists = null;
            DataTable datatable = new DataTable();
            IList list = new ArrayList();
            Pictures[] pictures;
            if (ExcelFileToDataTable(filepath, out datatable, out error) && GetPicturesFromExcelFile(filepath, out pictures, out error))
            {
                lists = new ArrayList[datatable.Rows.Count];
                //------------DataTable转换成IList[]--------------
                //数据
                int nRow = 0;
                foreach (DataRow row in datatable.Rows)
                {
                    lists[nRow] = new ArrayList(datatable.Columns.Count);
                    for (int i = 0; i <= datatable.Columns.Count - 1; i++)
                    {
                        lists[nRow].Add(row[i]);
                    }
                    nRow++;
                }
                //图片
                for (int i = 0; i < pictures.Length; i++)
                {
                    foreach (Picture picture in pictures[i])
                    {
                        try
                        {
                            //----把图片转换成System.Drawing.Image----
                            //MemoryStream mstream = new MemoryStream();
                            //mstream.Write(picture.Data, 0, picture.Data.Length);
                            //System.Drawing.Image image = System.Drawing.Image.FromStream(mstream);
                            //----Image放入IList------
                            //图片有可能越界
                            if (picture.UpperLeftRow <= datatable.Rows.Count && picture.UpperLeftColumn <= datatable.Columns.Count)
                            {
                                lists[picture.UpperLeftRow][picture.UpperLeftColumn] = picture.Data;
                            }

                        }
                        catch (System.Exception e)
                        {
                            error = error + e.Message;
                        }

                    }
                }

            }
            else
            {

                return false;
            }
            return true;
        } Excel 图片 aspose --------------------编程问答-------------------- 看看说明吧。 --------------------编程问答-------------------- http://www.oschina.net/question/565065_57457
你的答案在这里哟。 --------------------编程问答--------------------  这个官方都有DEMO  你想定义什么  --------------------编程问答-------------------- 除 --------------------编程问答-------------------- --------------------编程问答-------------------- 刚开始学,这个就是按给定的例子做的,谢谢各位。 --------------------编程问答-------------------- dll版本问题,不是最新的。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,