Passing date value to putValue() and trying to set a date format

Date Values Stored as Text Instead of DateTime in Cells

Issue Description

I’m experiencing an issue with date values in Excel cells using Aspose.Cells. When I programmatically insert a date value into a cell and apply date formatting, the value is initially stored as text rather than as a proper DateTime value.

Current Behavior

  • Date value is inserted into the cell as a string
  • Cell appears to contain the date but Excel treats it as text
  • Only after manually double-clicking the cell does Excel recognize it as a DateTime value
  • Once recognized, the date formatting (style.setNumber(14)) works correctly

Code Sample

// Date handling portion of my cell value function
if (options.isDate) {
  try {
    console.log('Date Value before parsing', value);
    const dateValue = new Date(value);
    console.log('Date Value after parsing', dateValue);
    
    if (!isNaN(dateValue.getTime())) {
      console.log(dateValue, 'is a valid date');
      dateValue.setHours(0, 0, 0, 0);
      console.log(dateValue, 'after setting hours to 0');
      cell.putValue(dateValue);
      console.log(dateValue, 'after putting value in cell');
      
      try {
        style.setNumber(14); // Standard date format
        console.log('Date format set successfully');
      } catch (e) {
        console.error('Primary date formatting failed: ', e);
        // Fallback to custom format
        try {
          style.setCustom('mm/dd/yyyy');
        } catch (innerErr) {
          console.log('Date format fallback failed', innerErr);
        }
      }
    } else {
      console.log('Invalid date value:', value);
      cell.putValue('');
    }
  } catch (err) {
    console.log('Error parsing date value:', err);
    cell.putValue('');
  }
}

Expected Behavior

The date value should be recognized as a DateTime data type immediately after insertion, without requiring manual interaction with the cell.

Questions

  1. Is there a specific method to ensure the cell value is stored as DateTime rather than text?
  2. Should I be using a different approach to insert JavaScript Date objects into cells?
  3. Are there any additional properties or methods I need to set to force Excel to recognize the value as a date?

I have attached the files and image for reference.

Any guidance on properly inserting DateTime values that are immediately recognized by Excel would be greatly appreciated.
image.png (68.1 KB)

@JayaPrakash031,

I checked your post and noticed the method you used in your code. I just wanted to confirm with you whether you’re using the Aspose.Cells Cloud SDK for Net or the Aspose.Cells for Net library.