Aspose 读取excel 问题

2019-01-02 21:05发布

问题:

 Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(stream);
                if (workbook.Worksheets.Count <= 0)//表中有3个表,3个表中数据不一样
                {
                    //return "错误";
                }
                MemoryStream testStream = new MemoryStream(); //内存流
                Worksheet ss = workbook.Worksheets[0]; //获得sheet1
                var s0 = ss.Cells;
                Worksheet ss1 = workbook.Worksheets[1];//获得表sheet2
                var s1 = ss1.Cells;
                Worksheet ss2 = workbook.Worksheets[2];//获得sheet3
                var s2 = ss2.Cells;
                //--01
                ss.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html);
                var sstr0 =  testStream.ToArray();
                string htmlText0 = Encoding.UTF8.GetString(sstr0); //读取流 (html源文件)
                //--02
                ss1.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html);
                var sstr1 = testStream.ToArray();
                string htmlText1 = Encoding.UTF8.GetString(sstr1); //读取流 (html源文件)
                //--03
                ss2.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html); //保存的数据都一样
                var sstr2 = testStream.ToArray();
                string htmlText2 = Encoding.UTF8.GetString(sstr2); //读取流 (html源文件)

为什么读取的数据  htmlText 内容 都是一样的???

回答1:

读取的内容都一样,而且都不是excel里的内容。。。



回答2:

MemoryStream testStream = new MemoryStream(); //内存流
////--01
testStream.Flush(); //清空流
sheet1.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html); //表1保存到流中
var sstr0 = testStream.ToArray();
string htmlText0 = Encoding.UTF8.GetString(sstr0); //读取流 (html源文件)
write("sheet1", htmlText0);
////--02
testStream.Flush(); //清空流
sheet2.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html);//表2保存到流中
var sstr1 = testStream.ToArray();
string htmlText1 = Encoding.UTF8.GetString(sstr1); //读取流 (html源文件)
write("sheet2", htmlText1);
////--03
testStream.Flush(); //清空流
sheet3.Workbook.Save(testStream, Aspose.Cells.SaveFormat.Html); //表3保存到流中
var sstr2 = testStream.ToArray();
string htmlText2 = Encoding.UTF8.GetString(sstr2); //读取流 (html源文件)
write("sheet3", htmlText2);
经测试
输出的三个文件中, 第一个文件是1个第3表中数据, 第二个文件是2个第3表中数据,第三个文件是3个第3表中数据,



标签: