Example #1
0
        private static void SetCellValue(XSSFCell oldCell, XSSFCell newCell)
        {
            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;

            case CellType.Unknown:
                newCell.SetCellValue(oldCell.StringCellValue);
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Копирование содержимого ячеек с соранением типа данных
        /// </summary>
        /// <param name="oldCell"></param>
        /// <param name="newCell"></param>
        private void CopyCellValue(HSSFCell oldCell, XSSFCell newCell)
        {
            switch (oldCell.CellType)
            {
            case CellType.String:
                newCell.SetCellValue(oldCell.StringCellValue);
                break;

            case CellType.Numeric:
                newCell.SetCellValue(oldCell.NumericCellValue);
                break;

            case CellType.Blank:
                newCell.SetCellType(CellType.Blank);
                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;

            default:
                break;
            }
        }
Example #3
0
        /**
         * @param oldCell
         * @param newCell
         * @param styleMap
         */
        public static void copyCell(HSSFCell oldCell, XSSFCell newCell, Dictionary <int, HSSFCellStyle> styleMap)
        {
            if (styleMap != null)
            {
                int           stHashCode      = oldCell.CellStyle.GetHashCode();
                HSSFCellStyle sourceCellStyle = styleMap[stHashCode];
                XSSFCellStyle destnCellStyle  = (XSSFCellStyle)newCell.CellStyle;
                if (sourceCellStyle == null)
                {
                    sourceCellStyle = (HSSFCellStyle)oldCell.Sheet.Workbook.CreateCellStyle();
                }
                destnCellStyle.CloneStyleFrom(oldCell.CellStyle);

                styleMap.Add(stHashCode, sourceCellStyle);
                newCell.CellStyle = destnCellStyle;
            }
            switch (oldCell.CellType)
            {
            case CellType.String:
                newCell.SetCellValue(oldCell.StringCellValue);
                break;

            case CellType.Numeric:
                newCell.SetCellValue(oldCell.NumericCellValue);
                break;

            case CellType.Blank:
                newCell.SetCellValue(string.Empty);     //!!!
                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;

            default:
                break;
            }
        }