當前位置: 首頁>>代碼示例>>C#>>正文


C# DataTable.AddColumnHandleDuplicate方法代碼示例

本文整理匯總了C#中System.Data.DataTable.AddColumnHandleDuplicate方法的典型用法代碼示例。如果您正苦於以下問題:C# DataTable.AddColumnHandleDuplicate方法的具體用法?C# DataTable.AddColumnHandleDuplicate怎麽用?C# DataTable.AddColumnHandleDuplicate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Data.DataTable的用法示例。


在下文中一共展示了DataTable.AddColumnHandleDuplicate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: readWholeWorkSheetWithIndex

        //TODO: quite a bit of duplication with the noindex version
        private bool 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 == -2)
                {
                    return false;
                }

                if (m_cellOffset < 0)
                {
                    return true;
                }

                //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)
                            {
                                table.AddColumnHandleDuplicate(m_cellsValues[i].ToString());
                            }
                            else
                            {
                                table.AddColumnHandleDuplicate(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);
                }

                //add the row
                if (m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
                {
                    table.Rows.Add(m_cellsValues);
                }
            }

            return true;
        }
開發者ID:Jennal,項目名稱:set,代碼行數:66,代碼來源:ExcelBinaryReader.cs

示例2: AsDataSet

        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;
        }
開發者ID:ningboliuwei,項目名稱:set,代碼行數:70,代碼來源:ExcelOpenXmlReader.cs

示例3: readWholeWorkSheetNoIndex

        private void readWholeWorkSheetNoIndex(bool triggerCreateColumns, DataTable table)
        {
            while (Read())
            {
                if (m_depth == m_maxRow) break;

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

                    triggerCreateColumns = false;
                    justAddedColumns = true;
                    table.BeginLoadData();
                }

                if (!justAddedColumns && m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
                {
                    table.Rows.Add(m_cellsValues);
                }
            }

            if (m_depth > 0 && !(_isFirstRowAsColumnNames && m_maxRow == 1))
            {
                table.Rows.Add(m_cellsValues);
            }
        }
開發者ID:Jennal,項目名稱:set,代碼行數:44,代碼來源:ExcelBinaryReader.cs

示例4: ReadDataSet

        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;
        }
開發者ID:Jennal,項目名稱:set,代碼行數:63,代碼來源:ExcelOpenXmlReader.cs


注:本文中的System.Data.DataTable.AddColumnHandleDuplicate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。