Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date parsing for Strict OpenXML spreadsheets #2702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jec006
Copy link

@jec006 jec006 commented Feb 21, 2024

Summary

This fixes the issue #2695, the parsing of dates in Strict mode isn't working (the dates are stored as strings in this mode - see https://www.loc.gov/preservation/digital/formats/fdd/fdd000401.shtml).

Test plan

> const ExcelJS = require('./excel')
> const fs = require('fs/promises')

> const fh = await fs.open('/Users/joshuacaldwell/Downloads/DateFormatStrict.xlsx')
> const bufferData = await fh.readFile()

> const workbook = new ExcelJS.Workbook();
> await workbook.xlsx.load(bufferData)
<ref *1> Workbook {
  category: undefined,
  company: '',
  created: 2024-02-16T21:36:25.000Z,
  description: undefined,
  keywords: undefined,
  manager: undefined,
  modified: 2024-02-16T21:37:00.000Z,
  properties: { date1904: false },
  calcProperties: {},
  _worksheets: [
    <1 empty item>,
    Worksheet {
      _workbook: [Circular *1],
      id: 1,
      orderNo: 0,
      _name: 'Sheet1',
      state: 'visible',
      _rows: [Array],
      _columns: [Array],
      _keys: {},
      _merges: {},
      rowBreaks: [],
      properties: [Object],
      pageSetup: [Object],
      headerFooter: null,
      dataValidations: [DataValidations],
      views: [Array],
      autoFilter: undefined,
      _media: [],
      sheetProtection: undefined,
      tables: {},
      pivotTables: undefined,
      conditionalFormattings: []
    }
  ],
  subject: undefined,
  title: undefined,
  views: [
    {
      x: 47440,
      y: -2080,
      width: 27640,
      height: 16440,
      visibility: 'visible'
    }
  ],
  media: [],
  pivotTables: [],
  _definedNames: DefinedNames { matrixMap: {} },
  _xlsx: XLSX { workbook: [Circular *1] },
  creator: 'Josh Caldwell',
  lastModifiedBy: 'Josh Caldwell',
  lastPrinted: undefined,
  language: undefined,
  revision: undefined,
  contentStatus: undefined,
  _themes: {
    theme1: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\r\n' +
      '<a:theme xmlns:a="http://purl.oclc.org/ooxml/drawingml/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="44546A"/></a:dk2><a:lt2><a:srgbClr val="E7E6E6"/></a:lt2><a:accent1><a:srgbClr val="4472C4"/></a:accent1><a:accent2><a:srgbClr val="ED7D31"/></a:accent2><a:accent3><a:srgbClr val="A5A5A5"/></a:accent3><a:accent4><a:srgbClr val="FFC000"/></a:accent4><a:accent5><a:srgbClr val="5B9BD5"/></a:accent5><a:accent6><a:srgbClr val="70AD47"/></a:accent6><a:hlink><a:srgbClr val="0563C1"/></a:hlink><a:folHlink><a:srgbClr val="954F72"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Calibri Light" panose="020F0302020204030204"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="游ゴシック Light"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="等线 Light"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/><a:font script="Armn" typeface="Arial"/><a:font script="Bugi" typeface="Leelawadee UI"/><a:font script="Bopo" typeface="Microsoft JhengHei"/><a:font script="Java" typeface="Javanese Text"/><a:font script="Lisu" typeface="Segoe UI"/><a:font script="Mymr" typeface="Myanmar Text"/><a:font script="Nkoo" typeface="Ebrima"/><a:font script="Olck" typeface="Nirmala UI"/><a:font script="Osma" typeface="Ebrima"/><a:font script="Phag" typeface="Phagspa"/><a:font script="Syrn" typeface="Estrangelo Edessa"/><a:font script="Syrj" typeface="Estrangelo Edessa"/><a:font script="Syre" typeface="Estrangelo Edessa"/><a:font script="Sora" typeface="Nirmala UI"/><a:font script="Tale" typeface="Microsoft Tai Le"/><a:font script="Talu" typeface="Microsoft New Tai Lue"/><a:font script="Tfng" typeface="Ebrima"/></a:majorFont><a:minorFont><a:latin typeface="Calibri" panose="020F0502020204030204"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="游ゴシック"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="等线"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/><a:font script="Armn" typeface="Arial"/><a:font script="Bugi" typeface="Leelawadee UI"/><a:font script="Bopo" typeface="Microsoft JhengHei"/><a:font script="Java" typeface="Javanese Text"/><a:font script="Lisu" typeface="Segoe UI"/><a:font script="Mymr" typeface="Myanmar Text"/><a:font script="Nkoo" typeface="Ebrima"/><a:font script="Olck" typeface="Nirmala UI"/><a:font script="Osma" typeface="Ebrima"/><a:font script="Phag" typeface="Phagspa"/><a:font script="Syrn" typeface="Estrangelo Edessa"/><a:font script="Syrj" typeface="Estrangelo Edessa"/><a:font script="Syre" typeface="Estrangelo Edessa"/><a:font script="Sora" typeface="Nirmala UI"/><a:font script="Tale" typeface="Microsoft Tai Le"/><a:font script="Talu" typeface="Microsoft New Tai Lue"/><a:font script="Tfng" typeface="Ebrima"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0%"><a:schemeClr val="phClr"><a:lumMod val="110%"/><a:satMod val="105%"/><a:tint val="67%"/></a:schemeClr></a:gs><a:gs pos="50%"><a:schemeClr val="phClr"><a:lumMod val="105%"/><a:satMod val="103%"/><a:tint val="73%"/></a:schemeClr></a:gs><a:gs pos="100%"><a:schemeClr val="phClr"><a:lumMod val="105%"/><a:satMod val="109%"/><a:tint val="81%"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0%"><a:schemeClr val="phClr"><a:satMod val="103%"/><a:lumMod val="102%"/><a:tint val="94%"/></a:schemeClr></a:gs><a:gs pos="50%"><a:schemeClr val="phClr"><a:satMod val="110%"/><a:lumMod val="100%"/><a:shade val="100%"/></a:schemeClr></a:gs><a:gs pos="100%"><a:schemeClr val="phClr"><a:lumMod val="99%"/><a:satMod val="120%"/><a:shade val="78%"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="6350" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800%"/></a:ln><a:ln w="12700" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800%"/></a:ln><a:ln w="19050" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/><a:miter lim="800%"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="57150" dist="19050" dir="5400000" algn="ctr" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="63%"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"><a:tint val="95%"/><a:satMod val="170%"/></a:schemeClr></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0%"><a:schemeClr val="phClr"><a:tint val="93%"/><a:satMod val="150%"/><a:shade val="98%"/><a:lumMod val="102%"/></a:schemeClr></a:gs><a:gs pos="50%"><a:schemeClr val="phClr"><a:tint val="98%"/><a:satMod val="130%"/><a:shade val="90%"/><a:lumMod val="103%"/></a:schemeClr></a:gs><a:gs pos="100%"><a:schemeClr val="phClr"><a:shade val="63%"/><a:satMod val="120%"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="5400000" scaled="0"/></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/><a:extLst><a:ext uri="{05A4C25C-085E-4340-85A3-A5531E510DB2}"><thm15:themeFamily xmlns:thm15="http://schemas.microsoft.com/office/thememl/2012/main" name="Office Theme" id="{62F939B6-93AF-4DB8-9C6B-D6C7DFDC589F}" vid="{4A3C46E8-61CC-4603-A589-7422A47A8E4A}"/></a:ext></a:extLst></a:theme>'
  }
}

> workbook.worksheets[0].getCell('A2')
<ref *1> Cell {
  _row: Row {
    _worksheet: Worksheet {
      _workbook: [Workbook],
      id: 1,
      orderNo: 0,
      _name: 'Sheet1',
      state: 'visible',
      _rows: [Array],
      _columns: [Array],
      _keys: {},
      _merges: {},
      rowBreaks: [],
      properties: [Object],
      pageSetup: [Object],
      headerFooter: null,
      dataValidations: [DataValidations],
      views: [Array],
      autoFilter: undefined,
      _media: [],
      sheetProtection: undefined,
      tables: {},
      pivotTables: undefined,
      conditionalFormattings: []
    },
    _number: 2,
    _cells: [ [Circular *1] ],
    style: {},
    _outlineLevel: 0,
    _hidden: undefined
  },
  _column: Column {
    _worksheet: Worksheet {
      _workbook: [Workbook],
      id: 1,
      orderNo: 0,
      _name: 'Sheet1',
      state: 'visible',
      _rows: [Array],
      _columns: [Array],
      _keys: {},
      _merges: {},
      rowBreaks: [],
      properties: [Object],
      pageSetup: [Object],
      headerFooter: null,
      dataValidations: [DataValidations],
      views: [Array],
      autoFilter: undefined,
      _media: [],
      sheetProtection: undefined,
      tables: {},
      pivotTables: undefined,
      conditionalFormattings: []
    },
    _number: 1,
    style: {},
    _outlineLevel: 0
  },
  _address: 'A2',
  _value: DateValue {
    model: {
      address: 'A2',
      styleId: undefined,
      value: 2024-02-09T00:00:00.000Z,
      type: 4,
      style: [Object]
    }
  },
  style: {
    numFmt: 'mm-dd-yy',
    font: {
      size: 12,
      color: [Object],
      name: 'Calibri',
      family: 2,
      scheme: 'minor'
    },
    fill: { type: 'pattern', pattern: 'none' }
  },
  _mergeCount: 0
}
> workbook.worksheets[0].getCell('A2').value 
2024-02-09T00:00:00.000Z

Related to source code (for typings update)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant