Exemplo n.º 1
0
        public void SstContinueRecordNoSplitFile()
        {
            // This is basically the same as the test above except it uses a
            // file created by Excel and has two CONTINUE records
            // (632 + 632 + 1 = 1265).

            string        fileName = TestsConfig.ReferenceFileFolder + "SstContinue.xls";
            List <Record> continueWorkbookRecords = null;

            Workbook.BytesReadCallback bytesReadCallback = delegate(List <Record> records)
            {
                continueWorkbookRecords = records;
            };
            XlsDocument xls = new XlsDocument(fileName, bytesReadCallback);

            Assert.IsNotNull(continueWorkbookRecords, "Workbook records list");
            Record sst = GetSstRecord(continueWorkbookRecords);

            Assert.IsNotNull(sst, "SST Record");
            Assert.AreEqual(2, sst.Continues.Count, "SST Continues");

            Assert.AreEqual(1, xls.Workbook.Worksheets.Count);
            Worksheet ws = xls.Workbook.Worksheets[0];

            Assert.AreEqual(1266, ws.Rows.Count);
            Assert.AreEqual(1265, ws.Rows.MaxRow);
            Assert.AreEqual("Test000632", ws.Rows[632].CellAtCol(1).Value);
            Assert.AreEqual("Test001264", ws.Rows[1264].CellAtCol(1).Value);
            Assert.AreEqual("Test001265", ws.Rows[1265].CellAtCol(1).Value);
        }
Exemplo n.º 2
0
        public void Read2007BlankBudgetWorksheet()
        {
            string        fileName = Path.Combine(TestsConfig.ReferenceFileFolder, "BlankBudgetWorksheet.xls");
            List <Record> workbookRecords;

            Workbook.BytesReadCallback workbookBytesReadCallback = delegate(List <Record> records)
            {
                workbookRecords = records;
            };
            XlsDocument xls = new XlsDocument(fileName, workbookBytesReadCallback);

            Assert.AreEqual(3, xls.Workbook.Worksheets.Count, "Number of worksheets");
            Assert.AreEqual("Budget", xls.Workbook.Worksheets[0].Name, "Worksheet 1 name");
            Assert.AreEqual("Income", xls.Workbook.Worksheets[1].Name, "Worksheet 2 name");
            Assert.AreEqual("Expenses", xls.Workbook.Worksheets[2].Name, "Worksheet 3 name");
            Worksheet sheet = xls.Workbook.Worksheets[0];

            Assert.AreEqual("See reverse for instructions and guidelines", sheet.Rows[6].CellAtCol(8).Value,
                            "Cell H6 hyperlink text");
            Assert.AreEqual("Budget Plan", sheet.Rows[7].CellAtCol(10).Value, "Cell J7 value");
            Assert.AreEqual("Administrative Support (12% of Revenue)", sheet.Rows[28].CellAtCol(7).Value,
                            "Cell G28 value");
            Assert.AreEqual(6801, sheet.Rows[10].CellAtCol(3).Value, "Cell C10 value");
            Assert.AreEqual("- 20", sheet.Rows[10].CellAtCol(6).Value, "Cell F10 Formula result value");
            Assert.AreEqual(0, sheet.Rows[10].CellAtCol(10).Value, "Cell J10 Multi-RK Value");
            Assert.AreEqual(0, sheet.Rows[10].CellAtCol(11).Value, "Cell J11 Multi-RK Value");
        }
Exemplo n.º 3
0
 // Token: 0x0600006F RID: 111 RVA: 0x0000464C File Offset: 0x0000364C
 internal XlsDocument(string fileName, Workbook.BytesReadCallback workbookBytesReadCallback)
 {
     if (string.IsNullOrEmpty(fileName))
     {
         throw new ArgumentException("Can't be null or Empty", "fileName");
     }
     if (!File.Exists(fileName))
     {
         throw new FileNotFoundException("Excel File not found", fileName);
     }
     this._ole2Doc = new Ole2Document();
     using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         this._ole2Doc.Load(fileStream);
     }
     this._workbook = new Workbook(this, this._ole2Doc.Streams[this._ole2Doc.Streams.GetIndex(org.in2bits.MyOle2.Directory.Biff8Workbook)].Bytes, workbookBytesReadCallback);
 }
Exemplo n.º 4
0
        internal XlsDocument(string fileName, Workbook.BytesReadCallback workbookBytesReadCallback)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("Can't be null or Empty", "fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("Excel File not found", fileName);
            }

            _ole2Doc = new Ole2Document();
            using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                _ole2Doc.Load(fileStream);
            }

            //TODO: SummaryInformationSection and DocumentSummaryInformationSections should be read by MyOle2
            _workbook = new Workbook(this, _ole2Doc.Streams[_ole2Doc.Streams.GetIndex(Cn.Vcredit.Common.MyOle2.Directory.Biff8Workbook)].Bytes, workbookBytesReadCallback);
        }
Exemplo n.º 5
0
        public void ReadYuanWorksheet()
        {
            string        fileName = Path.Combine(TestsConfig.ReferenceFileFolder, "Yuan697.xls");
            List <Record> workbookRecords;

            Workbook.BytesReadCallback workbookBytesReadCallback = delegate(List <Record> records)
            {
                workbookRecords = records;
            };
            XlsDocument xls = new XlsDocument(fileName, workbookBytesReadCallback);

            Assert.AreEqual(1, xls.Workbook.Worksheets.Count, "Number of worksheets");
            Assert.AreEqual("Sheet1", xls.Workbook.Worksheets[0].Name, "Worksheet 1 name");
            Worksheet sheet = xls.Workbook.Worksheets[0];

            Assert.AreEqual("num", sheet.Rows[1].CellAtCol(1).Value, "Cell A1 text");
            Assert.AreEqual("name", sheet.Rows[1].CellAtCol(2).Value, "Cell B1 text");
            Assert.AreEqual("sex", sheet.Rows[1].CellAtCol(3).Value, "Cell C1 text");
            Assert.AreEqual(2005151001, sheet.Rows[2].CellAtCol(1).Value, "Cell A2 value");
            Assert.AreEqual(2005151002, sheet.Rows[3].CellAtCol(1).Value, "Cell A3 value");
            Assert.AreEqual(2005151024, sheet.Rows[4].CellAtCol(1).Value, "Cell A4 value");
        }
Exemplo n.º 6
0
        public void SstContinueRecordNoSplit()
        {
            // This is an example of the CONTINUE record where the spillover
            // string is not actually split across two SST records.  Once the
            // first record is filled up with 632 strings, the 633th string
            // is placed in the CONTINUE record.
            //
            // This means that there are 632 whole 10-char strings (13 bytes
            // per 10-char string * 632 = 8216) in the first record with 1
            // whole 10-char string in the CONTINUE record.

            XlsDocumentDelegate continueDocDelegate = delegate(XlsDocument doc)
            {
                doc.Workbook.ShareStrings = true;
                Cells cells = doc.Workbook.Worksheets.Add("Sheet1").Cells;
                for (int i = 0; i < 633; i++)
                {
                    cells.Add(i + 1, 1, (i + 1000000001).ToString());
                }
                Assert.AreEqual(633, doc.Workbook.SharedStringTable.CountUnique, "Unique values in SST");
            };
            string continueFile = WriteDocument(continueDocDelegate);

            AssertPropertyViaExcelOle(1, 633, 1, continueFile, CellProperties.Value, "1000000633", "Read last string after CONTINUE");

            List <Record> continueWorkbookRecords = null;

            Workbook.BytesReadCallback bytesReadCallback = delegate(List <Record> records)
            {
                continueWorkbookRecords = records;
            };
            new XlsDocument(continueFile, bytesReadCallback);
            Assert.IsNotNull(continueWorkbookRecords, "Workbook records list");
            Record sst = GetSstRecord(continueWorkbookRecords);

            Assert.IsNotNull(sst, "SST Record");
            Assert.AreEqual(1, sst.Continues.Count, "SST Continues");
        }
Exemplo n.º 7
0
        public void SstTwoContinueRecords()
        {
            //8,216 bytes available for string records in SST Record
            //(before CONTINUE record is necessary)
            //8,223 bytes available for string records in CONTINUE Record
            //(before next CONTINUE record is necessary)
            //A 7-char single-byte (compressed unicode) text string, plus
            //the 3 bytes at the beginning of the Unicode
            //string data, gives 10 bytes per 7-char string record.
            //This gives us 821 7-char strings, the 822nd
            //spilling 4 bytes across to the first CONTINUE record.
            //Then another 821 (1,643 total), the 1,644th spilling 1 byte
            //over to the second CONTINUE Record.

            int stringsToWrite = 821;

            XlsDocumentDelegate docDelegate = delegate(XlsDocument doc)
            {
                doc.Workbook.ShareStrings = true;
                Cells cells = doc.Workbook.Worksheets.Add("Sheet1").Cells;
                for (int i = 0; i < stringsToWrite; i++)
                {
                    cells.Add(i + 1, 1, (i + 1000001).ToString());
                }
                Assert.AreEqual(stringsToWrite, doc.Workbook.SharedStringTable.CountUnique, "Unique values in SST");
            };
            string fileName = WriteDocument(docDelegate);

            List <Record> workbookRecords     = null;
            int           continueRecordCount = 0;

            Workbook.BytesReadCallback bytesReadCallback = delegate(List <Record> records)
            {
                workbookRecords = records;
            };
            new XlsDocument(fileName, bytesReadCallback);
            Assert.IsNotNull(workbookRecords, "Workbook records list");
            Record sst = GetSstRecord(workbookRecords);

            Assert.AreEqual(0, sst.Continues.Count, "SST CONTINUE Records");

            //reset
            workbookRecords     = null;
            continueRecordCount = 0;

            stringsToWrite = 822;
            fileName       = WriteDocument(docDelegate);
            new XlsDocument(fileName, bytesReadCallback);
            Assert.IsNotNull(workbookRecords, "Workbook records list");
            sst = GetSstRecord(workbookRecords);
            Assert.AreEqual(1, sst.Continues.Count, "SST CONTINUE Records");

            //reset
            workbookRecords     = null;
            continueRecordCount = 0;

            stringsToWrite = 1643;
            fileName       = WriteDocument(docDelegate);
            new XlsDocument(fileName, bytesReadCallback);
            Assert.IsNotNull(workbookRecords, "Workbook records list");
            sst = GetSstRecord(workbookRecords);
            Assert.AreEqual(1, sst.Continues.Count, "SST CONTINUE Records");

            //reset
            workbookRecords     = null;
            continueRecordCount = 0;

            stringsToWrite = 1644;
            fileName       = WriteDocument(docDelegate);
            new XlsDocument(fileName, bytesReadCallback);
            Assert.IsNotNull(workbookRecords, "Workbook records list");
            sst = GetSstRecord(workbookRecords);
            Assert.AreEqual(2, sst.Continues.Count, "SST CONTINUE Records");
            AssertPropertyViaExcelOle(1, 1644, 1, fileName, CellProperties.Value, (stringsToWrite + 1000000).ToString(),
                                      "Last String value via Excel OLE");
        }
Exemplo n.º 8
0
        public void SstContinueRecord()
        {
            //8,216 bytes available for data in SST Record
            //(before CONTINUE record is necessary)
            //A 7-char single-byte (compressed unicode) text string, plus
            //the 3 bytes at the beginning of the Unicode
            //string data, gives 10 bytes per 7-char string.
            //This gives us 821 7-char strings, the 822nd
            //spilling across to a CONTINUE record.

            XlsDocumentDelegate noContinueDocDelegate = delegate(XlsDocument doc)
            {
                doc.Workbook.ShareStrings = true;
                Cells cells = doc.Workbook.Worksheets.Add("Sheet1").Cells;
                for (int i = 0; i < 821; i++)
                {
                    cells.Add(i + 1, 1, (i + 1000001).ToString());
                }
                Assert.AreEqual(821, doc.Workbook.SharedStringTable.CountUnique, "Unique values in SST");
            };
            string noContinueFile = WriteDocument(noContinueDocDelegate);

            AssertPropertyViaExcelOle(1, 821, 1, noContinueFile, CellProperties.Value, "1000821", "Read last string before CONTINUE");

            List <Record> noContinueWorkbookRecords = null;

            Workbook.BytesReadCallback bytesReadCallback = delegate(List <Record> records)
            {
                noContinueWorkbookRecords = records;
            };
            new XlsDocument(noContinueFile, bytesReadCallback);
            Assert.IsNotNull(noContinueWorkbookRecords, "Workbook records list");
            Record sst = GetSstRecord(noContinueWorkbookRecords);

            Assert.IsNotNull(sst, "SST Record");
            Assert.AreEqual(0, sst.Continues.Count, "SST Continues");

            XlsDocumentDelegate continueDoc = delegate(XlsDocument doc)
            {
                doc.Workbook.ShareStrings = true;
                Cells cells = doc.Workbook.Worksheets.Add("Sheet1").Cells;
                for (int i = 0; i < 822; i++)
                {
                    cells.Add(i + 1, 1, (i + 1000001).ToString());
                }
                Assert.AreEqual(822, doc.Workbook.SharedStringTable.CountUnique, "Unique values in SST");
            };
            string continueFile = WriteDocument(continueDoc);

            AssertPropertyViaExcelOle(1, 822, 1, continueFile, CellProperties.Value, "1000822", "Read string split over to CONTINUE");

            List <Record> continueWorkbookRecords = null;

            bytesReadCallback = delegate(List <Record> records)
            {
                continueWorkbookRecords = records;
            };
            new XlsDocument(continueFile, bytesReadCallback);
            Assert.IsNotNull(continueWorkbookRecords, "Workbook records list");
            sst = GetSstRecord(continueWorkbookRecords);
            Assert.IsNotNull(sst, "SST Record");
            Assert.AreEqual(1, sst.Continues.Count, "SST CONTINUE Records");
        }
Exemplo n.º 9
0
        // Token: 0x060000CA RID: 202 RVA: 0x00005FE0 File Offset: 0x00004FE0
        private void ReadBytes(Bytes bytes, Workbook.BytesReadCallback bytesReadCallback)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException("bytes");
            }
            if (bytes.Length == 0)
            {
                throw new ArgumentException("can't be zero-length", "bytes");
            }
            SortedList <ushort, ushort> sortedList = new SortedList <ushort, ushort>();
            List <Record> all    = Record.GetAll(bytes);
            List <Record> list   = new List <Record>();
            List <Record> list2  = new List <Record>();
            List <Record> list3  = new List <Record>();
            List <Record> list4  = new List <Record>();
            Record        record = Record.Empty;
            SortedList <int, List <Record> > sortedList2 = new SortedList <int, List <Record> >();
            int num = -1;

            foreach (Record record2 in all)
            {
                if (num >= 0)
                {
                    if (!sortedList2.ContainsKey(num))
                    {
                        sortedList2[num] = new List <Record>();
                    }
                    sortedList2[num].Add(record2);
                    if (record2.RID == RID.EOF)
                    {
                        num++;
                    }
                }
                else if (record2.RID == RID.FONT)
                {
                    list.Add(record2);
                }
                else if (record2.RID == RID.FORMAT)
                {
                    list2.Add(record2);
                }
                else if (record2.RID == RID.XF)
                {
                    list3.Add(record2);
                }
                else if (record2.RID == RID.BOUNDSHEET)
                {
                    list4.Add(record2);
                }
                else if (record2.RID == RID.SST)
                {
                    record = record2;
                }
                else if (record2.RID == RID.EOF)
                {
                    num++;
                }
            }
            SortedList <ushort, Font>   sortedList3 = new SortedList <ushort, Font>();
            SortedList <ushort, string> sortedList4 = new SortedList <ushort, string>();

            new SortedList <ushort, XF>();
            ushort num2 = 0;

            foreach (Record record3 in list)
            {
                Font font = new Font(this._doc, record3.Data);
                SortedList <ushort, Font> sortedList5 = sortedList3;
                ushort num3 = num2;
                num2 = (ushort)(num3 + 1);
                sortedList5[num3] = font;
                this.Fonts.Add(font);
            }
            foreach (Record record4 in list2)
            {
                Bytes  data = record4.Data;
                string text = UnicodeBytes.Read(data.Get(2, data.Length - 2), 16);
                num2 = BitConverter.ToUInt16(data.Get(2).ByteArray, 0);
                sortedList4[num2] = text;
                this.Formats.Add(text);
            }
            num2 = 0;
            while ((int)num2 < list3.Count)
            {
                Record record5 = list3[(int)num2];
                Bytes  data2   = record5.Data;
                ushort key     = BitConverter.ToUInt16(data2.Get(0, 2).ByteArray, 0);
                ushort num4    = BitConverter.ToUInt16(data2.Get(2, 2).ByteArray, 0);
                if (sortedList3.ContainsKey(key))
                {
                    Font   font2 = sortedList3[key];
                    string format;
                    if (sortedList4.ContainsKey(num4))
                    {
                        format = sortedList4[num4];
                    }
                    else
                    {
                        if (!this._formats.ContainsKey(num4))
                        {
                            throw new ApplicationException(string.Format("Format {0} not found in read FORMAT records or standard/default FORMAT records.", num4));
                        }
                        format = this._formats[num4];
                    }
                    sortedList[num2] = this.XFs.Add(new XF(this._doc, record5.Data, font2, format));
                }
                num2 += 1;
            }
            this.XFs.XfIdxLookups = sortedList;
            if (record != Record.Empty)
            {
                this.SharedStringTable.ReadBytes(record);
            }
            if (bytesReadCallback != null)
            {
                bytesReadCallback(all);
            }
            for (int i = 0; i < list4.Count; i++)
            {
                this._worksheets.Add(list4[i], sortedList2[i]);
            }
        }
Exemplo n.º 10
0
 // Token: 0x060000BB RID: 187 RVA: 0x00005CE5 File Offset: 0x00004CE5
 internal Workbook(XlsDocument doc, Bytes bytes, Workbook.BytesReadCallback bytesReadCallback) : this(doc)
 {
     this.ReadBytes(bytes, bytesReadCallback);
 }