예제 #1
0
        private void ParseXlsStream(Stream fileStream)
        {
            using (m_file = fileStream)
            {
                m_hdr = XlsHeader.ReadHeader(m_file);
                XlsRootDirectory  dir           = new XlsRootDirectory(m_hdr);
                XlsDirectoryEntry workbookEntry = dir.FindEntry(WORKBOOK) ?? dir.FindEntry(BOOK);

                if (workbookEntry == null)
                {
                    throw new FileNotFoundException(Errors.ErrorStreamWorkbookNotFound);
                }
                if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
                {
                    throw new FormatException(Errors.ErrorWorkbookIsNotStream);
                }

                m_stream = new XlsBiffStream(m_hdr, workbookEntry.StreamFirstSector);

                ReadWorkbookGlobals();

                m_workbookData = new DataSet();

                for (int i = 0; i < m_sheets.Count; i++)
                {
                    if (ReadWorksheet(m_sheets[i]))
                    {
                        m_workbookData.Tables.Add(m_sheets[i].Data);
                    }
                }

                m_globals.SST = null;
                m_globals     = null;
                m_sheets      = null;
                m_stream      = null;
                m_hdr         = null;

                GC.Collect();
                GC.SuppressFinalize(this);
            }
        }
예제 #2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="file">Stream with source data</param>
        public ExcelDataReader(Stream file)
        {
            m_file = file; // new BufferedStream(file);
            m_hdr  = XlsHeader.ReadHeader(m_file);
            XlsRootDirectory  dir           = new XlsRootDirectory(m_hdr);
            XlsDirectoryEntry workbookEntry = dir.FindEntry("Workbook");

            if (workbookEntry == null)
            {
                workbookEntry = dir.FindEntry("Book");
            }
            if (workbookEntry == null)
            {
                throw new FileNotFoundException("Oops! Neither stream 'Workbook' nor 'Book' was found in file");
            }
            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                throw new FormatException("Oops! Workbook directory entry is not a Stream");
            }
            m_stream = new XlsBiffStream(m_hdr, workbookEntry.StreamFirstSector);
            ReadWorkbookGlobals();
            GC.Collect();
            m_workbookData = new DataSet();
            for (int i = 0; i < m_sheets.Count; i++)
            {
                if (ReadWorksheet(m_sheets[i]))
                {
                    m_workbookData.Tables.Add(m_sheets[i].Data);
                }
            }
            object[] obj  = m_workbookData.Tables[0].Rows[0].ItemArray;
            object[] obj2 = m_workbookData.Tables[0].Rows[1].ItemArray;
            object[] obj3 = m_workbookData.Tables[0].Rows[2].ItemArray;
            m_globals.SST = null;
            m_globals     = null;
            m_sheets      = null;
            m_stream      = null;
            m_hdr         = null;
            GC.Collect();
        }
예제 #3
0
        public ExcelDataReader(Stream file,
                               ref List <DataItemINTEX> listItems,
                               ref List <DataPalletINTEX> listPallets,
                               ref List <DataCaseINTEX> listCases)
        {
            XlsHeader         hdr           = XlsHeader.ReadHeader(file);
            XlsRootDirectory  dir           = new XlsRootDirectory(hdr);
            XlsDirectoryEntry workbookEntry = dir.FindEntry("Workbook");

            if (workbookEntry == null)
            {
                workbookEntry = dir.FindEntry("Book");
            }
            if (workbookEntry == null)
            {
                throw new FileNotFoundException("Oops! Neither stream 'Workbook' nor 'Book' was found in file");
            }
            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                throw new FormatException("Oops! Workbook directory entry is not a Stream");
            }
            m_stream = new XlsBiffStream(hdr, workbookEntry.StreamFirstSector);
            ReadWorkbookGlobals();
            GC.Collect();
            m_workbookData = new DataSet();
            // first sheet : boxes
            for (int iSheet = 0; iSheet < m_sheets.Count; ++iSheet)
            {
                if (string.Equals(m_sheets[iSheet].Name, "Articles", StringComparison.CurrentCultureIgnoreCase))
                {
                    listItems = new List <DataItemINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataItemINTEX item = new DataItemINTEX();
                                // ref
                                item._ref = ParseObjectToString(dt.Rows[iRow][0], "Ref");
                                // description
                                if (DBNull.Value != dt.Rows[iRow][1])
                                {
                                    item._description = (string)dt.Rows[iRow][1];
                                }
                                // UPC
                                item._UPC = ParseObjectToString(dt.Rows[iRow][2], "UPC");
                                // PCB
                                item._PCB = ParseObjectToInt(dt.Rows[iRow][3], "PCB");
                                // GenCode
                                item._gencode = ParseObjectToString(dt.Rows[iRow][4], "GenCode");
                                // weight
                                item._weight = ParseObjectToDouble(dt.Rows[iRow][5], "Weight");
                                // length / width / eight
                                item._length = ParseObjectToDouble(dt.Rows[iRow][6], "Length");
                                item._width  = ParseObjectToDouble(dt.Rows[iRow][7], "Width");;
                                item._height = ParseObjectToDouble(dt.Rows[iRow][8], "Height");;
                                listItems.Add(item);
                            }
                            catch (ExcelDataException ex)
                            { _log.InfoFormat("Row {0} - {1} is null or empty -> skipping...", iRow, ex.Message); }
                            catch (Exception ex)
                            { _log.ErrorFormat("Row = {0} -> {1}", iRow, ex.Message); }
                        }
                    }
                }
                // Pallets
                else if (string.Equals(m_sheets[iSheet].Name, "Palettes", StringComparison.CurrentCultureIgnoreCase))
                {
                    listPallets = new List <DataPalletINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataPalletINTEX pallet = new DataPalletINTEX();
                                if (DBNull.Value != dt.Rows[iRow][0])
                                {
                                    pallet._type = (string)dt.Rows[iRow][0];
                                }
                                pallet._length = ParseObjectToDouble(dt.Rows[iRow][1], "Pallet length");
                                pallet._width  = ParseObjectToDouble(dt.Rows[iRow][2], "Pallet width");
                                pallet._height = ParseObjectToDouble(dt.Rows[iRow][3], "Pallet height");
                                if (!DBNull.Value.Equals(dt.Rows[iRow][4]))
                                {
                                    pallet._weight = double.Parse((string)dt.Rows[iRow][4], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                listPallets.Add(pallet);
                            }
                            catch (ExcelDataException ex)
                            { _log.InfoFormat("Row {0} - {1} is null or empty -> skipping...", iRow, ex.Message); }
                            catch (Exception ex)
                            { _log.ErrorFormat("Row = {0} -> {1}", iRow, ex.Message); }
                        }
                    }
                }
                // Caisses
                else if (string.Equals(m_sheets[iSheet].Name, "Caisses", StringComparison.CurrentCultureIgnoreCase))
                {
                    listCases = new List <DataCaseINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataCaseINTEX caseItem = new DataCaseINTEX();
                                caseItem._ref       = ParseObjectToString(dt.Rows[iRow][0], "Ref");
                                caseItem._lengthExt = ParseObjectToDouble(dt.Rows[iRow][1], "Case length Ext.");
                                caseItem._widthExt  = ParseObjectToDouble(dt.Rows[iRow][2], "Case width Ext.");
                                caseItem._heightExt = ParseObjectToDouble(dt.Rows[iRow][3], "Case height Ext.");
                                if (!DBNull.Value.Equals(dt.Rows[iRow][4]))
                                {
                                    caseItem._lengthInt = double.Parse((string)dt.Rows[iRow][4], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][5]))
                                {
                                    caseItem._widthInt = double.Parse((string)dt.Rows[iRow][5], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][6]))
                                {
                                    caseItem._heightInt = double.Parse((string)dt.Rows[iRow][6], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][7]))
                                {
                                    caseItem._weight = double.Parse((string)dt.Rows[iRow][7], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                listCases.Add(caseItem);
                            }
                            catch (ExcelDataException ex)
                            { _log.InfoFormat("Row {0} - {1} is null or empty -> skipping...", iRow, ex.Message); }
                            catch (Exception ex)
                            { _log.Error(ex.ToString()); }
                        }
                    }
                }
            }

            m_globals.SST = null;
            m_globals     = null;
            m_sheets      = null;
            m_stream      = null;
            hdr           = null;
            GC.Collect();
        }
예제 #4
0
        private void ReadWorkBookGlobals()
        {
            //Read Header
            try
            {
                _Header = XlsHeader.ReadHeader(_File);
            }
            catch (Exceptions.HeaderException ex)
            {
                Fail(ex.Message);
                return;
            }
            catch (FormatException ex)
            {
                Fail(ex.Message);
                return;
            }

            var dir           = new XlsRootDirectory(_Header);
            var workbookEntry = dir.FindEntry(Workbook) ?? dir.FindEntry(Book);

            if (workbookEntry == null)
            {
                Fail(Errors.ErrorStreamWorkbookNotFound); return;
            }

            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                Fail(Errors.ErrorWorkbookIsNotStream); return;
            }

            _BiffStream = new XlsBiffStream(_Header, workbookEntry.StreamFirstSector);

            _WorkbookGlobals = new XlsWorkbookGlobals();

            _BiffStream.Seek(0, SeekOrigin.Begin);

            var rec = _BiffStream.Read();
            var bof = rec as XlsBiffBOF;

            if (bof == null || bof.Type != BIFFTYPE.WorkbookGlobals)
            {
                Fail(Errors.ErrorWorkbookGlobalsInvalidData); return;
            }

            var sst = false;

            _Version = bof.Version;
            _Sheets  = new List <XlsWorksheet>();

            while (null != (rec = _BiffStream.Read()))
            {
                switch (rec.ID)
                {
                case BIFFRECORDTYPE.INTERFACEHDR:
                    _WorkbookGlobals.InterfaceHdr = (XlsBiffInterfaceHdr)rec;
                    break;

                case BIFFRECORDTYPE.BOUNDSHEET:
                    var sheet = (XlsBiffBoundSheet)rec;

                    if (sheet.Type != XlsBiffBoundSheet.SheetType.Worksheet)
                    {
                        break;
                    }

                    sheet.IsV8        = IsV8();
                    sheet.UseEncoding = _Encoding;

                    _Sheets.Add(new XlsWorksheet(_WorkbookGlobals.Sheets.Count, sheet));
                    _WorkbookGlobals.Sheets.Add(sheet);

                    break;

                case BIFFRECORDTYPE.MMS:
                    _WorkbookGlobals.MMS = rec;
                    break;

                case BIFFRECORDTYPE.COUNTRY:
                    _WorkbookGlobals.Country = rec;
                    break;

                case BIFFRECORDTYPE.CODEPAGE:

                    _WorkbookGlobals.CodePage = (XlsBiffSimpleValueRecord)rec;

                    try
                    {
                        _Encoding = /*Encoding.GetEncoding(_WorkbookGlobals.CodePage.Value);*/ Encoding.Unicode;
                    }
                    catch (ArgumentException)
                    {
                        // Warning - Password protection
                        // TODO: Attach to ILog
                    }

                    break;

                case BIFFRECORDTYPE.FONT:
                case BIFFRECORDTYPE.FONT_V34:
                    _WorkbookGlobals.Fonts.Add(rec);
                    break;

                case BIFFRECORDTYPE.FORMAT:
                case BIFFRECORDTYPE.FORMAT_V23:
                    _WorkbookGlobals.Formats.Add(rec);
                    break;

                case BIFFRECORDTYPE.XF:
                case BIFFRECORDTYPE.XF_V4:
                case BIFFRECORDTYPE.XF_V3:
                case BIFFRECORDTYPE.XF_V2:
                    _WorkbookGlobals.ExtendedFormats.Add(rec);
                    break;

                case BIFFRECORDTYPE.SST:
                    _WorkbookGlobals.SST = (XlsBiffSST)rec;
                    sst = true;
                    break;

                case BIFFRECORDTYPE.CONTINUE:
                    if (!sst)
                    {
                        break;
                    }
                    var contSst = (XlsBiffContinue)rec;
                    _WorkbookGlobals.SST.Append(contSst);
                    break;

                case BIFFRECORDTYPE.EXTSST:
                    _WorkbookGlobals.ExtSST = rec;
                    sst = false;
                    break;

                case BIFFRECORDTYPE.PROTECT:
                case BIFFRECORDTYPE.PASSWORD:
                case BIFFRECORDTYPE.PROT4REVPASSWORD:
                    //IsProtected
                    break;

                case BIFFRECORDTYPE.EOF:
                    if (_WorkbookGlobals.SST != null)
                    {
                        _WorkbookGlobals.SST.ReadStrings();
                    }
                    return;

                default:
                    continue;
                }
            }
        }
        private void readWorkBookGlobals()
        {
            //Read Header
            try
            {
                m_hdr = XlsHeader.ReadHeader(m_file);
            }
            catch (Exceptions.HeaderException ex)
            {
                fail(ex.Message);
                return;
            }
            catch (FormatException ex)
            {
                fail(ex.Message);
                return;
            }

            XlsRootDirectory  dir           = new XlsRootDirectory(m_hdr);
            XlsDirectoryEntry workbookEntry = dir.FindEntry(WORKBOOK) ?? dir.FindEntry(BOOK);

            if (workbookEntry == null)
            {
                fail(Errors.ErrorStreamWorkbookNotFound); return;
            }

            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                fail(Errors.ErrorWorkbookIsNotStream); return;
            }

            m_stream = new XlsBiffStream(m_hdr, workbookEntry.StreamFirstSector, workbookEntry.IsEntryMiniStream, dir, this);

            m_globals = new XlsWorkbookGlobals();

            m_stream.Seek(0, SeekOrigin.Begin);

            XlsBiffRecord rec = m_stream.Read();
            XlsBiffBOF    bof = rec as XlsBiffBOF;

            if (bof == null || bof.Type != BIFFTYPE.WorkbookGlobals)
            {
                fail(Errors.ErrorWorkbookGlobalsInvalidData); return;
            }

            bool sst = false;

            m_version = bof.Version;
            m_sheets  = new List <XlsWorksheet>();

            while (null != (rec = m_stream.Read()))
            {
                switch (rec.ID)
                {
                case BIFFRECORDTYPE.INTERFACEHDR:
                    m_globals.InterfaceHdr = (XlsBiffInterfaceHdr)rec;
                    break;

                case BIFFRECORDTYPE.BOUNDSHEET:
                    XlsBiffBoundSheet sheet = (XlsBiffBoundSheet)rec;

                    if (sheet.Type != XlsBiffBoundSheet.SheetType.Worksheet)
                    {
                        break;
                    }

                    sheet.IsV8        = isV8();
                    sheet.UseEncoding = m_encoding;
                    LogManager.Log(this).Debug("BOUNDSHEET IsV8={0}", sheet.IsV8);

                    m_sheets.Add(new XlsWorksheet(m_globals.Sheets.Count, sheet));
                    m_globals.Sheets.Add(sheet);

                    break;

                case BIFFRECORDTYPE.MMS:
                    m_globals.MMS = rec;
                    break;

                case BIFFRECORDTYPE.COUNTRY:
                    m_globals.Country = rec;
                    break;

                case BIFFRECORDTYPE.CODEPAGE:

                    m_globals.CodePage = (XlsBiffSimpleValueRecord)rec;

                    try
                    {
                        m_encoding = Encoding.GetEncoding(m_globals.CodePage.Value);
                    }
                    catch (ArgumentException)
                    {
                        // Warning - Password protection
                        // TODO: Attach to ILog
                    }

                    break;

                case BIFFRECORDTYPE.FONT:
                case BIFFRECORDTYPE.FONT_V34:
                    m_globals.Fonts.Add(rec);
                    break;

                case BIFFRECORDTYPE.FORMAT_V23:
                {
                    var fmt = (XlsBiffFormatString)rec;
                    fmt.UseEncoding = m_encoding;
                    m_globals.Formats.Add((ushort)m_globals.Formats.Count, fmt);
                }
                break;

                case BIFFRECORDTYPE.FORMAT:
                {
                    var fmt = (XlsBiffFormatString)rec;
                    m_globals.Formats.Add(fmt.Index, fmt);
                }
                break;

                case BIFFRECORDTYPE.XF:
                case BIFFRECORDTYPE.XF_V4:
                case BIFFRECORDTYPE.XF_V3:
                case BIFFRECORDTYPE.XF_V2:
                    m_globals.ExtendedFormats.Add(rec);
                    break;

                case BIFFRECORDTYPE.SST:
                    m_globals.SST = (XlsBiffSST)rec;
                    sst           = true;
                    break;

                case BIFFRECORDTYPE.CONTINUE:
                    if (!sst)
                    {
                        break;
                    }
                    XlsBiffContinue contSST = (XlsBiffContinue)rec;
                    m_globals.SST.Append(contSST);
                    break;

                case BIFFRECORDTYPE.EXTSST:
                    m_globals.ExtSST = rec;
                    sst = false;
                    break;

                case BIFFRECORDTYPE.PROTECT:
                case BIFFRECORDTYPE.PASSWORD:
                case BIFFRECORDTYPE.PROT4REVPASSWORD:
                    //IsProtected
                    break;

                case BIFFRECORDTYPE.EOF:
                    if (m_globals.SST != null)
                    {
                        m_globals.SST.ReadStrings();
                    }
                    return;

                default:
                    continue;
                }
            }
        }
예제 #6
0
        private void readWorkBookGlobals()
        {
            XlsBiffRecord record;
            bool          flag;

            try
            {
                this.m_hdr = XlsHeader.ReadHeader(this.m_file);
            }
            catch (HeaderException exception)
            {
                this.fail(exception.Message);
                return;
            }
            catch (FormatException exception2)
            {
                this.fail(exception2.Message);
                return;
            }
            XlsRootDirectory  rootDir = new XlsRootDirectory(this.m_hdr);
            XlsDirectoryEntry entry   = rootDir.FindEntry("Workbook") ?? rootDir.FindEntry("Book");

            if (entry != null)
            {
                if (entry.EntryType != STGTY.STGTY_STREAM)
                {
                    this.fail("Error: Workbook directory entry is not a Stream.");
                    return;
                }
                this.m_stream  = new XlsBiffStream(this.m_hdr, entry.StreamFirstSector, entry.IsEntryMiniStream, rootDir);
                this.m_globals = new XlsWorkbookGlobals();
                this.m_stream.Seek(0, SeekOrigin.Begin);
                XlsBiffBOF fbof = this.m_stream.Read() as XlsBiffBOF;
                if ((fbof == null) || (fbof.Type != BIFFTYPE.WorkbookGlobals))
                {
                    this.fail("Error reading Workbook Globals - Stream has invalid data.");
                    return;
                }
                flag           = false;
                this.m_version = fbof.Version;
                this.m_sheets  = new List <XlsWorksheet>();
            }
            else
            {
                this.fail("Error: Neither stream 'Workbook' nor 'Book' was found in file.");
                return;
            }
            while ((record = this.m_stream.Read()) != null)
            {
                BIFFRECORDTYPE iD = record.ID;
                if (iD <= BIFFRECORDTYPE.COUNTRY)
                {
                    switch (iD)
                    {
                    case BIFFRECORDTYPE.FORMAT_V23:
                    {
                        XlsBiffFormatString str = (XlsBiffFormatString)record;
                        str.UseEncoding = this.m_encoding;
                        this.m_globals.Formats.Add((ushort)this.m_globals.Formats.Count, str);
                        break;
                    }

                    case BIFFRECORDTYPE.FONT:
                        goto Label_031C;

                    case BIFFRECORDTYPE.EOF:
                        goto Label_03F3;

                    case BIFFRECORDTYPE.CODEPAGE:
                        goto Label_02E4;

                    case BIFFRECORDTYPE.XF_V2:
                        goto Label_0395;

                    case BIFFRECORDTYPE.CONTINUE:
                        goto Label_03C0;

                    case BIFFRECORDTYPE.BOUNDSHEET:
                    {
                        XlsBiffBoundSheet refSheet = (XlsBiffBoundSheet)record;
                        if (refSheet.Type == XlsBiffBoundSheet.SheetType.Worksheet)
                        {
                            refSheet.IsV8        = this.isV8();
                            refSheet.UseEncoding = this.m_encoding;
                            this.m_sheets.Add(new XlsWorksheet(this.m_globals.Sheets.Count, refSheet));
                            this.m_globals.Sheets.Add(refSheet);
                        }
                        break;
                    }

                    case BIFFRECORDTYPE.COUNTRY:
                        this.m_globals.Country = record;
                        break;
                    }
                }
                else if (iD <= BIFFRECORDTYPE.EXTSST)
                {
                    switch (iD)
                    {
                    case BIFFRECORDTYPE.SST:
                        this.m_globals.SST = (XlsBiffSST)record;
                        flag = true;
                        break;

                    case BIFFRECORDTYPE.EXTSST:
                        this.m_globals.ExtSST = record;
                        flag = false;
                        break;

                    case BIFFRECORDTYPE.XF:
                        goto Label_0395;

                    case BIFFRECORDTYPE.INTERFACEHDR:
                        this.m_globals.InterfaceHdr = (XlsBiffInterfaceHdr)record;
                        break;

                    case BIFFRECORDTYPE.MMS:
                        goto Label_02C0;
                    }
                }
                else if (iD <= BIFFRECORDTYPE.FONT_V34)
                {
                    if ((iD != BIFFRECORDTYPE.PROT4REVPASSWORD) && (iD == BIFFRECORDTYPE.FONT_V34))
                    {
                        goto Label_031C;
                    }
                }
                else
                {
                    switch (iD)
                    {
                    case BIFFRECORDTYPE.XF_V3:
                    case BIFFRECORDTYPE.XF_V4:
                        goto Label_0395;

                    case BIFFRECORDTYPE.FORMAT:
                    {
                        XlsBiffFormatString str2 = (XlsBiffFormatString)record;
                        this.m_globals.Formats.Add(str2.Index, str2);
                        break;
                    }
                    }
                }
                continue;
Label_02C0:
                this.m_globals.MMS = record;
                continue;
Label_02E4:
                this.m_globals.CodePage = (XlsBiffSimpleValueRecord)record;
                try
                {
                    this.m_encoding = Encoding.GetEncoding(this.m_globals.CodePage.Value);
                }
                catch (ArgumentException)
                {
                }
                continue;
Label_031C:
                this.m_globals.Fonts.Add(record);
                continue;
Label_0395:
                this.m_globals.ExtendedFormats.Add(record);
                continue;
Label_03C0:
                if (flag)
                {
                    XlsBiffContinue fragment = (XlsBiffContinue)record;
                    this.m_globals.SST.Append(fragment);
                }
                continue;
Label_03F3:
                if (this.m_globals.SST != null)
                {
                    this.m_globals.SST.ReadStrings();
                }
                return;
            }
        }
예제 #7
0
        public ExcelDataReader(Stream file,
                               ref List <DataItemINTEX> listItems,
                               ref List <DataPalletINTEX> listPallets,
                               ref List <DataCaseINTEX> listCases)
        {
            XlsHeader         hdr           = XlsHeader.ReadHeader(file);
            XlsRootDirectory  dir           = new XlsRootDirectory(hdr);
            XlsDirectoryEntry workbookEntry = dir.FindEntry("Workbook");

            if (workbookEntry == null)
            {
                workbookEntry = dir.FindEntry("Book");
            }
            if (workbookEntry == null)
            {
                throw new FileNotFoundException("Oops! Neither stream 'Workbook' nor 'Book' was found in file");
            }
            if (workbookEntry.EntryType != STGTY.STGTY_STREAM)
            {
                throw new FormatException("Oops! Workbook directory entry is not a Stream");
            }
            m_stream = new XlsBiffStream(hdr, workbookEntry.StreamFirstSector);
            ReadWorkbookGlobals();
            GC.Collect();
            m_workbookData = new DataSet();
            // first sheet : boxes
            for (int iSheet = 0; iSheet < m_sheets.Count; ++iSheet)
            {
                if (string.Equals(m_sheets[iSheet].Name, "Articles", StringComparison.CurrentCultureIgnoreCase))
                {
                    listItems = new List <DataItemINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataItemINTEX item = new DataItemINTEX();
                                item._ref         = (string)dt.Rows[iRow][0];
                                item._description = (string)dt.Rows[iRow][1];
                                if (DBNull.Value != dt.Rows[iRow][2])
                                {
                                    item._UPC = (string)dt.Rows[iRow][2];
                                }
                                if (DBNull.Value != dt.Rows[iRow][3])
                                {
                                    item._PCB = Convert.ToInt32((string)dt.Rows[iRow][3]);
                                }
                                if (DBNull.Value != dt.Rows[iRow][4])
                                {
                                    item._gencode = (string)dt.Rows[iRow][4];
                                }
                                item._weight = double.Parse((string)dt.Rows[iRow][5], System.Globalization.CultureInfo.InvariantCulture);
                                item._length = double.Parse((string)dt.Rows[iRow][6], System.Globalization.CultureInfo.InvariantCulture);
                                item._width  = double.Parse((string)dt.Rows[iRow][7], System.Globalization.CultureInfo.InvariantCulture);
                                item._height = double.Parse((string)dt.Rows[iRow][8], System.Globalization.CultureInfo.InvariantCulture);
                                listItems.Add(item);
                            }
                            catch (Exception /*ex*/)
                            {
                            }
                        }
                    }
                }
                // Pallets
                else if (string.Equals(m_sheets[iSheet].Name, "Palettes", StringComparison.CurrentCultureIgnoreCase))
                {
                    listPallets = new List <DataPalletINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataPalletINTEX pallet = new DataPalletINTEX();
                                pallet._type   = (string)dt.Rows[iRow][0];
                                pallet._length = double.Parse((string)dt.Rows[iRow][1], System.Globalization.CultureInfo.InvariantCulture);
                                pallet._width  = double.Parse((string)dt.Rows[iRow][2], System.Globalization.CultureInfo.InvariantCulture);
                                pallet._height = double.Parse((string)dt.Rows[iRow][3], System.Globalization.CultureInfo.InvariantCulture);
                                if (!DBNull.Value.Equals(dt.Rows[iRow][4]))
                                {
                                    pallet._weight = double.Parse((string)dt.Rows[iRow][4], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                listPallets.Add(pallet);
                            }
                            catch (Exception /*ex*/)
                            {
                            }
                        }
                    }
                }
                // Caisses
                else if (string.Equals(m_sheets[iSheet].Name, "Caisses", StringComparison.CurrentCultureIgnoreCase))
                {
                    listCases = new List <DataCaseINTEX>();
                    if (ReadWorksheet(m_sheets[iSheet]))
                    {
                        DataTable dt = m_sheets[iSheet].Data;
                        for (int iRow = 4; iRow < dt.Rows.Count; ++iRow)
                        {
                            try
                            {
                                DataCaseINTEX caseItem = new DataCaseINTEX();
                                caseItem._ref       = (string)dt.Rows[iRow][0];
                                caseItem._lengthExt = double.Parse((string)dt.Rows[iRow][1], System.Globalization.CultureInfo.InvariantCulture);
                                caseItem._widthExt  = double.Parse((string)dt.Rows[iRow][2], System.Globalization.CultureInfo.InvariantCulture);
                                caseItem._heightExt = double.Parse((string)dt.Rows[iRow][3], System.Globalization.CultureInfo.InvariantCulture);
                                if (!DBNull.Value.Equals(dt.Rows[iRow][4]))
                                {
                                    caseItem._lengthInt = double.Parse((string)dt.Rows[iRow][4], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][5]))
                                {
                                    caseItem._widthInt = double.Parse((string)dt.Rows[iRow][5], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][6]))
                                {
                                    caseItem._heightInt = double.Parse((string)dt.Rows[iRow][6], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                if (!DBNull.Value.Equals(dt.Rows[iRow][7]))
                                {
                                    caseItem._weight = double.Parse((string)dt.Rows[iRow][7], System.Globalization.CultureInfo.InvariantCulture);
                                }
                                listCases.Add(caseItem);
                            }
                            catch (Exception /*ex*/)
                            {
                            }
                        }
                    }
                }
            }

            m_globals.SST = null;
            m_globals     = null;
            m_sheets      = null;
            m_stream      = null;
            hdr           = null;
            GC.Collect();
        }