Exemplo n.º 1
0
        public System.Data.DataSet AsDataSet(bool convertOADateTime)
        {
            if (!m_isValid) return null;

            DataSet dataset = new DataSet();

            for (int sheetIndex = 0; sheetIndex < m_workbook.Sheets.Count; sheetIndex++)
            {
                DataTable table = new DataTable(m_workbook.Sheets[sheetIndex].Name);

                ReadSheetGlobals(m_workbook.Sheets[sheetIndex]);

                if (m_workbook.Sheets[sheetIndex].Dimension == null) continue;

                m_depth = 0;
                m_emptyRowCount = 0;

                // Reada Columns
                //Console.WriteLine("Read Columns");
                if (!m_isFirstRowAsColumnNames)
                {
                    // No Sheet Columns
                    for (int i = 0; i < m_workbook.Sheets[sheetIndex].ColumnsCount; i++)
                    {
                        table.Columns.Add(null, typeof(Object));
                    }
                }
                else if (ReadSheetRow(m_workbook.Sheets[sheetIndex]))
                {
                    // Read Sheet Columns
                    //Console.WriteLine("Read Sheet Columns");
                    for (int index = 0; index < m_cellsValues.Length; index++)
                    {
                        if (m_cellsValues[index] != null && m_cellsValues[index].ToString().Length > 0)
                        {
                            table.AddColumnHandleDuplicate(m_cellsValues[index].ToString());
                        }
                        else
                        {
                            table.AddColumnHandleDuplicate(string.Concat(COLUMN, index));
                        }
                    }
                }
                else
                {
                    continue;
                }

                // Read Sheet Rows
                //Console.WriteLine("Read Sheet Rows");
                table.BeginLoadData();
                while (ReadSheetRow(m_workbook.Sheets[sheetIndex]))
                {
                    table.Rows.Add(m_cellsValues);
                }
                if (table.Rows.Count > 0)
                {
                    dataset.Tables.Add(table);
                }

                // Read HyperLinks
                //Console.WriteLine("Read Sheet HyperLinks:{0}",table.Rows.Count);
                ReadHyperLinks(m_workbook.Sheets[sheetIndex],table);

                table.EndLoadData();
            }
            dataset.AcceptChanges();
            dataset.FixDataTypes();
            return dataset;
        }
Exemplo n.º 2
0
        public DataSet AsDataSet(bool convertOADateTime)
        {
            if (!m_isValid) return null;

            if (m_isClosed) return m_workbookData;

            ConvertOaDate = convertOADateTime;
            m_workbookData = new DataSet();

            for (int index = 0; index < ResultsCount; index++)
            {
                DataTable table = readWholeWorkSheet(m_sheets[index]);

                if (null != table)
                    m_workbookData.Tables.Add(table);
            }

            m_file.Close();
            m_isClosed = true;
            m_workbookData.AcceptChanges();
            m_workbookData.FixDataTypes();

            return m_workbookData;
        }
Exemplo n.º 3
0
        private System.Data.DataSet ReadDataSet()
        {
            DataSet dataset=new DataSet();

            var demensionDict=DetectDemension();

            for (int sheetIndex=0; sheetIndex<m_workbook.Sheets.Count; sheetIndex++) {
                var sheet=m_workbook.Sheets[sheetIndex];
                var table=new DataTable(m_workbook.Sheets[sheetIndex].Name);

                ReadSheetGlobals(sheet);
                sheet.Dimension=demensionDict[sheetIndex];

                if (sheet.Dimension==null) {
                    continue;
                }

                m_depth=0;
                m_emptyRowCount=0;

                // Reada Columns
                //Console.WriteLine("Read Columns");
                if (!m_isFirstRowAsColumnNames) {
                    // No Sheet Columns
                    //Console.WriteLine("SheetName:{0}, ColumnCount:{1}", sheet.Name, sheet.ColumnsCount);
                    for (int i=0; i<sheet.ColumnsCount; i++) {
                        table.Columns.Add(null, typeof(Object));
                    }
                } else if (ReadSheetRow(sheet)) {
                    // Read Sheet Columns
                    //Console.WriteLine("Read Sheet Columns");
                    for (int index=0; index<m_cellsValues.Length; index++) {
                        if (m_cellsValues[index]!=null&&m_cellsValues[index].ToString().Length>0) {
                            table.AddColumnHandleDuplicate(m_cellsValues[index].ToString());
                        } else {
                            table.AddColumnHandleDuplicate(string.Concat(COLUMN, index));
                        }
                    }
                } else {
                    continue;
                }

                // Read Sheet Rows
                //Console.WriteLine("Read Sheet Rows");
                table.BeginLoadData();
                //Console.WriteLine("SheetIndex Is:{0},Name:{1}",sheetIndex,sheet.Name);
                while (ReadSheetRow(sheet)) {
                    table.Rows.Add(m_cellsValues);
                }
                if (table.Rows.Count>0) {
                    dataset.Tables.Add(table);
                }

                // Read HyperLinks
                //Console.WriteLine("Read Sheet HyperLinks:{0}",table.Rows.Count);
                ReadHyperLinks(sheet, table);

                table.EndLoadData();
            }
            dataset.AcceptChanges();
            dataset.FixDataTypes();
            return dataset;
        }