コード例 #1
0
	    private void fail(string message)
	    {
	        m_exceptionMessage = message;
	        m_isValid = false;

	        m_file.Close();
	        m_isClosed = true;

	        m_workbookData = null;
	        m_sheets = null;
	        m_stream = null;
	        m_globals = null;
	        m_encoding = null;
	        m_hdr = null;
	    }
コード例 #2
0
	    private void Dispose(bool disposing)
	    {
	        // Check to see if Dispose has already been called.
	        if (!disposed)
	        {
	            if (disposing)
	            {
	                if (m_workbookData != null) m_workbookData.Dispose();

	                if (m_sheets != null) m_sheets.Clear();
	            }

	            m_workbookData = null;
	            m_sheets = null;
	            m_stream = null;
	            m_globals = null;
	            m_encoding = null;
	            m_hdr = null;

	            disposed = true;
	        }
	    }
コード例 #3
0
	    private void readWorkBookGlobals()
	    {
	        //Read Header
	        try
	        {
	            m_hdr = XlsHeader.ReadHeader(m_file);
	        }
	        catch (HeaderException ex)
	        {
	            fail(ex.Message);
	            return;
	        }
	        catch (FormatException ex)
	        {
	            fail(ex.Message);
	            return;
	        }

	        var dir = new XlsRootDirectory(m_hdr);
	        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; }

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

	        m_globals = new XlsWorkbookGlobals();

	        m_stream.Seek(0, SeekOrigin.Begin);

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

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

	        var 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:
	                    var sheet = (XlsBiffBoundSheet)rec;

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

	                    sheet.IsV8 = isV8();
	                    sheet.UseEncoding = m_encoding;

	                    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:
	                case BIFFRECORDTYPE.FORMAT_V23:
	                    m_globals.Formats.Add(rec);
	                    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;
	                    var 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;
	            }
	        }
	    }