Exemplo n.º 1
0
        private void readWholeWorkSheetWithIndex(XlsBiffIndex idx, bool triggerCreateColumns, DataTable table)
        {
            m_dbCellAddrs = idx.DbCellAddresses;

            for (int index = 0; index < m_dbCellAddrs.Length; index++)
            {
                if (m_depth == m_maxRow)
                {
                    break;
                }

                // init reading data
                m_cellOffset = findFirstDataCellOffset((int)m_dbCellAddrs[index]);
                if (m_cellOffset < 0)
                {
                    return;
                }

                //DataTable columns
                if (triggerCreateColumns)
                {
                    if (_isFirstRowAsColumnNames && readWorkSheetRow() || (_isFirstRowAsColumnNames && m_maxRow == 1))
                    {
                        for (int i = 0; i < m_maxCol; i++)
                        {
                            if (m_cellsValues[i] != null && m_cellsValues[i].ToString().Length > 0)
                            {
                                Helpers.AddColumnHandleDuplicate(table, m_cellsValues[i].ToString());
                            }
                            else
                            {
                                Helpers.AddColumnHandleDuplicate(table, string.Concat(COLUMN, i));
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < m_maxCol; i++)
                        {
                            table.Columns.Add(null, typeof(Object));
                        }
                    }

                    triggerCreateColumns = false;

                    table.BeginLoadData();
                }

                while (readWorkSheetRow())
                {
                    table.Rows.Add(m_cellsValues);
                }

                if (m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
                {
                    table.Rows.Add(m_cellsValues);
                }
            }
        }
Exemplo n.º 2
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;
            }

            #region Если в текущем файле MS Biff нет индекса или он не находится в самом начале то основные данные в таблицах не находятся и выводится только минимум.
            //if (null == idx)
            //{
            //	// There is a record before the index! Chech his type and see the MS Biff Documentation
            //	return false;
            //}
            #endregion

            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;
                }
                var 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);
        }