当前位置: 首页>>代码示例>>C#>>正文


C# DocumentFormat.Read方法代码示例

本文整理汇总了C#中DocumentFormat.Read方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentFormat.Read方法的具体用法?C# DocumentFormat.Read怎么用?C# DocumentFormat.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DocumentFormat的用法示例。


在下文中一共展示了DocumentFormat.Read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDataSetFromExcelTab

        public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
        {
            var rtrn = new DataSet();
            var dataTable = new DataTable(SheetName);
            rtrn.Tables.Add(dataTable);

            while (reader.Read())
            {
                if (reader.ElementType != typeof(Row))
                {
                    continue;
                }

                var row = (Row)reader.LoadCurrentElement();

                if (row.RowIndex >= 4)
                {
                    var blankRow = new List<object>();
                    for (var i = 0; i < dataTable.Columns.Count; i++)
                    {
                        blankRow.Add(null);
                    }
                    dataTable.Rows.Add(blankRow.ToArray());
                }

                foreach (var openXmlElement in row.ChildElements)
                {
                    var cell = (Cell) openXmlElement;
                    var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
                    var excelColumnNumber = ExcelColumnNameToNumber(withoutNumbers);

                    if (row.RowIndex == 2)
                    {
                        var cellValue = GetCellValue(workbookPart, cell);
                        if (dataTable.Columns.Contains(cellValue))
                        {
                            for (var i = 1; i < int.MaxValue; i++)
                            {
                                var columnName = string.Format("{0}_{1}", cellValue, i);
                                if (dataTable.Columns.Contains(columnName))
                                {
                                    continue;
                                }
                                dataTable.Columns.Add(columnName);
                                break;
                            }
                        }
                        else
                        {
                            dataTable.Columns.Add(cellValue);
                        }
                    }
                    else if (row.RowIndex >= 4)
                    {
                        var cellValue = GetCellValue(workbookPart, cell);

                        if (string.IsNullOrEmpty(cellValue))
                        {
                            continue;
                        }

                        var columnIndex = excelColumnNumber - 1;
                        if (columnIndex < dataTable.Columns.Count)
                        {
                            dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
                        }
                    }
                }
            }

            DumpEmptyColumns(rtrn);
            DumpEmptyRows(rtrn);
            
            for (var i = dataTable.Rows.Count - 1; i >= 0; i--)
            {
                var distinctValue = dataTable.Rows[i][1].ToString();
                var name = dataTable.Rows[i][3].ToString();
                if (((distinctValue != "yes" && distinctValue != "no" && !string.IsNullOrEmpty(distinctValue))) || (name.ToLower().Contains("copy and paste")))
                {
                    dataTable.Rows[i].Delete();
                }
            }
            dataTable.AcceptChanges();

            return rtrn;
        }
开发者ID:dknipper,项目名称:ExcelDocumentProcessor,代码行数:86,代码来源:ParentMigrationVA.cs

示例2: GetDataSetFromExcelTab

        public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
        {
            var rtrn = new DataSet();
            var dataTable = new DataTable(SheetName);
            rtrn.Tables.Add(dataTable);

            while (reader.Read())
            {
                if (reader.ElementType != typeof(Row))
                {
                    continue;
                }

                var row = (Row)reader.LoadCurrentElement();

                if (row.RowIndex >= BodyStartRowIndex)
                {
                    var blankRow = new List<object>();
                    for (var i = 0; i < dataTable.Columns.Count; i++)
                    {
                        blankRow.Add(null);
                    }
                    dataTable.Rows.Add(blankRow.ToArray());
                }

                // ReSharper disable once LoopCanBePartlyConvertedToQuery
                foreach (var openXmlElement in row.ChildElements)
                {
                    var cell = (Cell) openXmlElement;
                    if (row.RowIndex == HeaderRowIndex)
                    {
                        var cellValue = GetCellValue(workbookPart, cell);
                        if (dataTable.Columns.Contains(cellValue))
                        {
                            for (var i = 1; i < int.MaxValue; i++)
                            {
                                var columnName = string.Format("{0}_{1}", cellValue, i);
                                if (dataTable.Columns.Contains(columnName))
                                {
                                    continue;
                                }
                                dataTable.Columns.Add(columnName);
                                break;
                            }
                        }
                        else
                        {
                            dataTable.Columns.Add(cellValue);
                        }
                    }
                    else if (row.RowIndex >= BodyStartRowIndex)
                    {
                        var cellValue = GetCellValue(workbookPart, cell);

                        if (string.IsNullOrEmpty(cellValue))
                        {
                            continue;
                        }

                        var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
                        var columnIndex = (ExcelColumnNameToNumber(withoutNumbers) - 1);

                        if (columnIndex < dataTable.Columns.Count)
                        {
                            dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
                        }
                    }
                }
            }

            DumpEmptyColumns(rtrn);
            DumpEmptyRows(rtrn);

            return rtrn;
        }
开发者ID:dknipper,项目名称:ExcelDocumentProcessor,代码行数:75,代码来源:Standard.cs

示例3: GetDataSetFromExcelTab

        public override DataSet GetDataSetFromExcelTab(DocumentFormat.OpenXml.OpenXmlReader reader, DocumentFormat.OpenXml.Packaging.WorkbookPart workbookPart)
        {
            var rtrn = new DataSet();
            var dataTable = new DataTable(SheetName);
            var dataTableBenchmarkPa = new DataTable(string.Format("{0} Benchmark Set PA", SheetName.Substring(0, 7)));

            dataTableBenchmarkPa.Columns.Add("Equity Benchmark Set");
            dataTableBenchmarkPa.Columns.Add("Set Name");
            dataTableBenchmarkPa.Columns.Add("Set ID");
            dataTableBenchmarkPa.Columns.Add("Lookup Row");

            rtrn.Tables.Add(dataTable);
            rtrn.Tables.Add(dataTableBenchmarkPa);

            while (reader.Read())
            {
                if (reader.ElementType != typeof(Row))
                {
                    continue;
                }

                var row = (Row)reader.LoadCurrentElement();

                if (row.RowIndex >= 3)
                {
                    var blankRow = new List<object>();
                    for (var i = 0; i < dataTable.Columns.Count; i++)
                    {
                        blankRow.Add(null);
                    }
                    dataTable.Rows.Add(blankRow.ToArray());
                }

                var currentSet = string.Empty;
                foreach (var openXmlElement in row.ChildElements)
                {
                    var cell = (Cell) openXmlElement;
                    var withoutNumbers = Regex.Replace(cell.CellReference, "[0-9]", "");
                    var excelColumnNumber = ExcelColumnNameToNumber(withoutNumbers);

                    if (row.RowIndex >= 2 && excelColumnNumber <= 12)
                    {
                        if (row.RowIndex == 2)
                        {
                            var cellValue = GetCellValue(workbookPart, cell);
                            if (dataTable.Columns.Contains(cellValue))
                            {
                                for (var i = 1; i < int.MaxValue; i++)
                                {
                                    var columnName = string.Format("{0}_{1}", cellValue, i);
                                    if (dataTable.Columns.Contains(columnName))
                                    {
                                        continue;
                                    }
                                    dataTable.Columns.Add(columnName);
                                    break;
                                }
                            }
                            else
                            {
                                dataTable.Columns.Add(cellValue);
                            }
                        }
                        else if (row.RowIndex >= 3)
                        {
                            var cellValue = GetCellValue(workbookPart, cell);

                            if (string.IsNullOrEmpty(cellValue))
                            {
                                continue;
                            }

                            var columnIndex = excelColumnNumber - 1;
                            if (columnIndex < dataTable.Columns.Count)
                            {
                                dataTable.Rows[dataTable.Rows.Count - 1][columnIndex] = cellValue.Trim();
                            }
                        }
                    }


                    if (row.RowIndex%3 != 0 || excelColumnNumber < 13 || excelColumnNumber > 28)
                    {
                        continue;
                    }

                    if (excelColumnNumber == 13)
                    {
                        var cellValue = GetCellValue(workbookPart, cell);
                        currentSet = cellValue.Trim();
                    }

                    if (string.IsNullOrEmpty(currentSet))
                    {
                        continue;
                    }

                    var setId = excelColumnNumber - 14;
                    if (setId < 1 || setId > 14)
                    {
//.........这里部分代码省略.........
开发者ID:dknipper,项目名称:ExcelDocumentProcessor,代码行数:101,代码来源:PeerGroupData.cs


注:本文中的DocumentFormat.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。