<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using NPOI.SS.UserModel;
using System.Collections;
using System.Diagnostics;

namespace FileHelpers.ExcelNPOIStorage
{
    public static class NPOIUtils
    {
        public static object GetCellValue(ICell cell)
        {
            switch (cell.CellType) {
                default:
                    return null;
                case CellType.Blank:
                    return null;
                case CellType.Boolean:
                    return cell.BooleanCellValue;
                case CellType.String:
                    return cell.StringCellValue;
                case CellType.Numeric:
                    if (DateUtil.IsCellDateFormatted(cell))
                        return cell.DateCellValue;
                    else
                        return cell.NumericCellValue;
                case CellType.Error:
                    return cell.ErrorCellValue;
                case CellType.Formula:
                    return string.Concat("=", cell.CellFormula);
            }
        }

        public static void SetCellValue(ICell cell, object value)
        {
            if (value == null)
                cell.SetCellValue(null as string);

            else if (value is string ||
                     value is String)
                cell.SetCellValue(value as string);

            else if (value is bool ||
                     value is Boolean)
                cell.SetCellValue((bool) value);

            else if (value is DateTime) {
                //It works
                var wb = cell.Sheet.Workbook;
                var cellStyle = wb.CreateCellStyle();
                // Can only be created once for each custom format, the code below is wrong
                cellStyle.DataFormat = cell.Sheet.Workbook.GetCreationHelper().CreateDataFormat().GetFormat("dd/mm/yyyy" );
                cell.CellStyle = cellStyle;                
                cell.SetCellValue((DateTime) value);
            }<commit_msg>Saving with date column in tests works<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;
using NPOI.SS.UserModel;
using System.Collections;
using System.Diagnostics;

namespace FileHelpers.ExcelNPOIStorage
{
    public static class NPOIUtils
    {
        public static object GetCellValue(ICell cell)
        {
            switch (cell.CellType) {
                default:
                    return null;
                case CellType.Blank:
                    return null;
                case CellType.Boolean:
                    return cell.BooleanCellValue;
                case CellType.String:
                    return cell.StringCellValue;
                case CellType.Numeric:
                    if (DateUtil.IsCellDateFormatted(cell))
                        return cell.DateCellValue;
                    else
                        return cell.NumericCellValue;
                case CellType.Error:
                    return cell.ErrorCellValue;
                case CellType.Formula:
                    return string.Concat("=", cell.CellFormula);
            }
        }

        public static void SetCellValue(ICell cell, object value)
        {
            if (value == null)
                cell.SetCellValue(null as string);

            else if (value is string ||
                     value is String)
                cell.SetCellValue(value as string);

            else if (value is bool ||
                     value is Boolean)
                cell.SetCellValue((bool) value);

            else if (value is DateTime) {
                //It works
                var wb = cell.Sheet.Workbook;
                var cellStyle = wb.CreateCellStyle();
                cellStyle.DataFormat = cell.Sheet.Workbook.GetCreationHelper().CreateDataFormat().GetFormat("dd/mm/yyyy" );
                cell.CellStyle = cellStyle;                
                cell.SetCellValue((DateTime) value);
            }
{'fraction_non_alphanumeric': 0.0708740295517155, 'fraction_numerical': 0.0, 'mean_word_length': 1.3577331759149942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5095304', 'n_tokens_mistral': 983, 'n_tokens_neox': 916, 'n_words': 242}