예제 #1
0
        private void SetMinMaxRow(int rowIndex, XlsBiffRow row)
        {
            if (!RowOffsetMap.TryGetValue(rowIndex, out var rowOffset))
            {
                rowOffset = new XlsRowOffset();
                rowOffset.MinCellOffset      = int.MaxValue;
                rowOffset.MaxCellOffset      = int.MinValue;
                rowOffset.MaxOverlapRowIndex = int.MinValue;
                RowOffsetMap.Add(rowIndex, rowOffset);
            }

            rowOffset.Record = row;
        }
		private bool moveToNextRecordNoIndex()
		{
			//seek from current row record to start of cell data where that cell relates to the next row record
			XlsBiffRow rowRecord = m_currentRowRecord;

			if (rowRecord == null)
				return false;
			
			if (rowRecord.RowIndex < m_depth)
			{
				m_stream.Seek(rowRecord.Offset + rowRecord.Size, SeekOrigin.Begin);
				do
				{
					if (m_stream.Position >= m_stream.Size)
						return false;

					var record = m_stream.Read();
					if (record is XlsBiffEOF)
						return false;

					rowRecord = record as XlsBiffRow;

				} while (rowRecord == null || rowRecord.RowIndex < m_depth);
			}

			m_currentRowRecord = rowRecord;
			//m_depth = m_currentRowRecord.RowIndex;

			//we have now found the row record for the new row, the we need to seek forward to the first cell record
			XlsBiffBlankCell cell = null;
			do
			{
				if (m_stream.Position >= m_stream.Size)
					return false;

				var record = m_stream.Read();
				if (record is XlsBiffEOF)
					return false;

				if (record.IsCell)
				{
					var candidateCell = record as XlsBiffBlankCell;
					if (candidateCell != null)
					{
						if (candidateCell.RowIndex == m_currentRowRecord.RowIndex)
							cell = candidateCell;
					}
				}
			} while (cell == null);

			m_cellOffset = cell.Offset;
			m_canRead = readWorkSheetRow();


			//read last row
			//if (!m_canRead && m_depth > 0) m_canRead = true;

			//if (!m_canRead && m_dbCellAddrsIndex < (m_dbCellAddrs.Length - 1))
			//{
			//	m_dbCellAddrsIndex++;
			//	m_cellOffset = findFirstDataCellOffset((int)m_dbCellAddrs[m_dbCellAddrsIndex]);

			//	m_canRead = readWorkSheetRow();
			//}

			return m_canRead;
		}
		private bool readWorkSheetGlobals(XlsWorksheet sheet, out XlsBiffIndex idx, out XlsBiffRow row)
		{
			idx = null;
			row = null;

			m_stream.Seek((int)sheet.DataOffset, SeekOrigin.Begin);

			XlsBiffBOF bof = m_stream.Read() as XlsBiffBOF;
			if (bof == null || bof.Type != BIFFTYPE.Worksheet) return false;

			//DumpBiffRecords();

			XlsBiffRecord rec = m_stream.Read();
			if (rec == null) return false;
			if (rec is XlsBiffIndex)
			{
				idx = rec as XlsBiffIndex;
			}
			else if (rec is XlsBiffUncalced)
			{
				// Sometimes this come before the index...
				idx = m_stream.Read() as XlsBiffIndex;
			}

			//if (null == idx)
			//{
			//	// There is a record before the index! Chech his type and see the MS Biff Documentation
			//	return false;
			//}

			if (idx != null)
			{
				idx.IsV8 = isV8();
				LogManager.Log(this).Debug("INDEX IsV8={0}", idx.IsV8);
			}
				


			XlsBiffRecord trec;
			XlsBiffDimensions dims = null;

			do
			{
				trec = m_stream.Read();
				if (trec.ID == BIFFRECORDTYPE.DIMENSIONS)
				{
					dims = (XlsBiffDimensions)trec;
					break;
				}

			} while (trec != null && trec.ID != BIFFRECORDTYPE.ROW);

			//if we are already on row record then set that as the row, otherwise step forward till we get to a row record
			if (trec.ID == BIFFRECORDTYPE.ROW)
				row = (XlsBiffRow)trec;

			XlsBiffRow rowRecord = null;
			while (rowRecord == null)
			{
				if (m_stream.Position >= m_stream.Size)
					break;
				var thisRec = m_stream.Read();

				LogManager.Log(this).Debug("finding rowRecord offset {0}, rec: {1}", thisRec.Offset, thisRec.ID);
				if (thisRec is XlsBiffEOF)
					break;
				rowRecord = thisRec as XlsBiffRow;
			}

			if (rowRecord != null)
				LogManager.Log(this).Debug("Got row {0}, rec: id={1},rowindex={2}, rowColumnStart={3}, rowColumnEnd={4}", rowRecord.Offset, rowRecord.ID, rowRecord.RowIndex, rowRecord.FirstDefinedColumn, rowRecord.LastDefinedColumn);

			row = rowRecord;

            if (dims != null) {
                dims.IsV8 = isV8();
				LogManager.Log(this).Debug("dims IsV8={0}", dims.IsV8);
                m_maxCol = dims.LastColumn - 1;

				//handle case where sheet reports last column is 1 but there are actually more
				if (m_maxCol <= 0 && rowRecord != null)
				{
					m_maxCol = rowRecord.LastDefinedColumn;
				}
				
                m_maxRow = (int)dims.LastRow;
                sheet.Dimensions = dims;
            } else {
                m_maxCol = 256;
                m_maxRow = (int)idx.LastExistingRow;
            }

			if (idx != null && idx.LastExistingRow <= idx.FirstExistingRow)
			{
				return false;
			}
			else if (row == null)
			{
				return false;
			}

			m_depth = 0;

			return true;
		}
예제 #4
0
		private bool readWorkSheetGlobals(XlsWorksheet sheet, out XlsBiffIndex idx, out XlsBiffRow row)
		{
			idx = null;
			row = null;

			m_stream.Seek((int)sheet.DataOffset, SeekOrigin.Begin);

			XlsBiffBOF bof = m_stream.Read() as XlsBiffBOF;
			if (bof == null || bof.Type != BIFFTYPE.Worksheet) return false;

			//DumpBiffRecords();

			XlsBiffRecord rec = m_stream.Read();
			if (rec == null) return false;
			if (rec is XlsBiffIndex)
			{
				idx = rec as XlsBiffIndex;
			}
			else if (rec is XlsBiffUncalced)
			{
				// Sometimes this come before the index...
				idx = m_stream.Read() as XlsBiffIndex;
			}

			//if (null == idx)
			//{
			//	// There is a record before the index! Chech his type and see the MS Biff Documentation
			//	return false;
			//}

			if (idx != null)
				idx.IsV8 = isV8();

			XlsBiffRecord trec;
			XlsBiffDimensions dims = null;

			do
			{
				trec = m_stream.Read();
				if (trec.ID == BIFFRECORDTYPE.DIMENSIONS)
				{
					dims = (XlsBiffDimensions)trec;
					break;
				}

			} while (trec != null && trec.ID != BIFFRECORDTYPE.ROW);

			//if we are already on row record then set that as the row, otherwise step forward till we get to a row record
			if (trec.ID == BIFFRECORDTYPE.ROW)
				row = (XlsBiffRow)trec;

			XlsBiffRow rowRecord = null;
			while (rowRecord == null)
			{
				if (m_stream.Position >= m_stream.Size)
					break;
				XlsBiffRecord thisRec = m_stream.Read();
				if (thisRec is XlsBiffEOF)
					break;
				rowRecord = thisRec as XlsBiffRow;
			}

			row = rowRecord;

			m_maxCol = 256;

			if (dims != null)
			{
				dims.IsV8 = isV8();
				m_maxCol = dims.LastColumn - 1;
				sheet.Dimensions = dims;
			}

			m_maxRow = idx == null ? (int)dims.LastRow : (int)idx.LastExistingRow;

			if (idx != null && idx.LastExistingRow <= idx.FirstExistingRow)
			{
				return false;
			}
			else if (row == null)
			{
				return false;
			}

			m_depth = 0;

			return true;
		}