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


C# ISheet.ShiftRows方法代码示例

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


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

示例1: CopyRow

        public static IRow CopyRow(ISheet sheet, int sourceRowIndex, int targetRowIndex)
        {
            if (sourceRowIndex == targetRowIndex)
                throw new ArgumentException("sourceIndex and targetIndex cannot be same");
            // Get the source / new row
            IRow newRow = sheet.GetRow(targetRowIndex);
            IRow sourceRow = sheet.GetRow(sourceRowIndex);

            // If the row exist in destination, push down all rows by 1 else create a new row
            if (newRow != null)
            {
                sheet.ShiftRows(targetRowIndex, sheet.LastRowNum, 1);
            }
            else
            {
                newRow = sheet.CreateRow(targetRowIndex);
            }

            // Loop through source columns to add to new row
            for (int i = sourceRow.FirstCellNum; i < sourceRow.LastCellNum; i++)
            {
                // Grab a copy of the old/new cell
                ICell oldCell = sourceRow.GetCell(i);

                // If the old cell is null jump to next cell
                if (oldCell == null)
                {
                    continue;
                }
                ICell newCell = newRow.CreateCell(i);

                if (oldCell.CellStyle != null)
                {
                    // apply style from old cell to new cell 
                    newCell.CellStyle = oldCell.CellStyle;
                }

                // If there is a cell comment, copy
                if (oldCell.CellComment != null)
                {
                    newCell.CellComment = oldCell.CellComment;
                }

                // If there is a cell hyperlink, copy
                if (oldCell.Hyperlink != null)
                {
                    newCell.Hyperlink = oldCell.Hyperlink;
                }

                // Set the cell data type
                newCell.SetCellType(oldCell.CellType);

                // Set the cell data value
                switch (oldCell.CellType)
                {
                    case CellType.Blank:
                        newCell.SetCellValue(oldCell.StringCellValue);
                        break;
                    case CellType.Boolean:
                        newCell.SetCellValue(oldCell.BooleanCellValue);
                        break;
                    case CellType.Error:
                        newCell.SetCellErrorValue(oldCell.ErrorCellValue);
                        break;
                    case CellType.Formula:
                        newCell.SetCellFormula(oldCell.CellFormula);
                        break;
                    case CellType.Numeric:
                        newCell.SetCellValue(oldCell.NumericCellValue);
                        break;
                    case CellType.String:
                        newCell.SetCellValue(oldCell.RichStringCellValue);
                        break;
                }
            }

            // If there are are any merged regions in the source row, copy to new row
            for (int i = 0; i < sheet.NumMergedRegions; i++)
            {
                CellRangeAddress cellRangeAddress = sheet.GetMergedRegion(i);
                if (cellRangeAddress.FirstRow == sourceRow.RowNum)
                {
                    CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.RowNum,
                            (newRow.RowNum +
                                    (cellRangeAddress.LastRow - cellRangeAddress.FirstRow
                                            )),
                            cellRangeAddress.FirstColumn,
                            cellRangeAddress.LastColumn);
                    sheet.AddMergedRegion(newCellRangeAddress);
                }
            }
            return newRow;
        }
开发者ID:kennethahn,项目名称:npoi,代码行数:93,代码来源:SheetUtil.cs

示例2: RowFilter

        private static void RowFilter(ImportError importError, ISheet sheet)
        {
            int counter = 0;
            var res = (from err in importError
                       select err.IndexOfRow).Distinct();

            foreach (var rowNum in res)
            {
                sheet.ShiftRows(rowNum, rowNum, 1 - rowNum + counter);
                counter++;
            }

            for (int rowNum = counter + 1; rowNum <= sheet.LastRowNum; rowNum++)
            {
                IRow row = sheet.GetRow(rowNum);
                sheet.RemoveRow(row);
            }
        }
开发者ID:ZLLselfRedeem,项目名称:zllinmitu,代码行数:18,代码来源:ExcelUtil.cs

示例3: SetValue

        public override void SetValue(ISheet sheet, JToken token)
        {
            JArray data;
            if (this.Each == "$root")
            {
                data = (JArray)token;
            }
            else
            {
                data = (JArray)token[Each];
            }
            var row = sheet.GetRow(RowIndex);

            var grouprows = ExcelGroupRow.GetGroupRows(data, TreeCode);

            for (int i = 0; i < data.Count; i++)
            {
                var item = data[i];
                foreach (var cellTemplate in Cells)
                {
                    var cell = row.GetCell(cellTemplate.ColIndex);
                    var val = item[cellTemplate.Bind];

                        cellTemplate.SetCellValue(cell, val);
                }
                if (i != data.Count - 1) {
                    row = sheet.CopyRow(row.RowNum, row.RowNum + 1);
                }
            }

            var groups = grouprows.Values.OrderByDescending(o => o.TreeCode).ToList();
            var b = JsonConvert.SerializeObject(groups);
            foreach (var grouprow in groups)
            {

                sheet.GroupRow(grouprow.StartIndex + RowIndex+1, grouprow.EndIndex + RowIndex);
            }
            if (data.Count == 0) {
                sheet.ShiftRows(row.RowNum+1, sheet.LastRowNum, -1);
            }
        }
开发者ID:alittletired,项目名称:mysoft,代码行数:41,代码来源:ExcelMetaData.cs

示例4: InsertRow

 static IRow InsertRow(ISheet sheet, int index)
 {
     if (sheet.LastRowNum > index)
         sheet.ShiftRows(index, sheet.LastRowNum, 1, true, false);
     IRow row = sheet.GetRow(index);
     if (row == null)
         row = sheet.CreateRow(index);
     return row;
 }
开发者ID:BachelorEric,项目名称:ModelFirst,代码行数:9,代码来源:ExcelHelper.cs


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