Пример #1
0
        public static void CopyCell(this ISheet sheet, ICell sourceCell, CellLocation targetLocation)
        {
            if (sourceCell == null)
            {
                sheet.RemoveCell(targetLocation);
                return;
            }

            var targetCell = sheet.GetCell(targetLocation);

            if (targetCell == null)
            {
                targetCell = sheet.GetCellWithPromise(targetLocation);
                if (targetCell.ColumnIndex != sourceCell.ColumnIndex)
                {
                    sheet.SetColumnWidth(targetCell.ColumnIndex, sheet.GetColumnWidth(sourceCell.ColumnIndex));
                }
            }

            if (sourceCell.CellStyle != null)
            {
                targetCell.CellStyle = sourceCell.CellStyle;
            }
            if (sourceCell.CellComment != null)
            {
                targetCell.CellComment = sourceCell.CellComment;
            }
            if (sourceCell.Hyperlink != null)
            {
                targetCell.Hyperlink = sourceCell.Hyperlink;
            }
            targetCell.SetCellType(sourceCell.CellType);

            switch (sourceCell.CellType)
            {
            case CellType.Numeric:
                targetCell.SetCellValue(sourceCell.NumericCellValue);
                break;

            case CellType.String:
                targetCell.SetCellValue(sourceCell.RichStringCellValue);
                break;

            case CellType.Formula:
                targetCell.SetCellFormula(sourceCell.CellFormula);
                break;

            case CellType.Blank:
                targetCell.SetCellValue(sourceCell.StringCellValue);
                break;

            case CellType.Boolean:
                targetCell.SetCellValue(sourceCell.BooleanCellValue);
                break;

            case CellType.Error:
                targetCell.SetCellErrorValue(sourceCell.ErrorCellValue);
                break;
            }
        }
Пример #2
0
 public static void SetCellValue(this ISheet sheet, CellLocation cellLocation, object value)
 {
     sheet.GetCellWithPromise(cellLocation).SetValue(value);
 }