2020-01-28 05:02:07 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "utf-8" / >
< title > SheetJS Community Edition< / title >
< link rel = "icon" href = "data:image/x-icon;base64,AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAKCgr/FRUX/xYWGP8YGBr/GRkb/xsbHP8dHR7/Hh4f/x4eIP8fHyD/ICAh/yMjJP8kJCX/JiYo/ygoKv8pKSr/LCwu/y0tLv80NDT/QUFC/0ZGR/9MTE7/UFBR/1JSUv9bW1v/XFxc/2BgYP9hYWP/aGhp/2xsbP9ycnL/d3d3/3l5e/98fHz/f3+A/2dn/P9z3a//cNX8/4CAgP+Xl5f/nZ2e/56en/+fn5//n5+h/6amp/+rq6v/rKys/7CvsP+zs7T/uLi5/7u7u/+8vLz/wMDA/8fHx//Kysr/zc3N/9HR0f/d3d3/3t7e/+Xl5f/q6ur/6+vr/+3t7f/z8/P/9fX1//b29v/39/f/+Pj4//n5+f/6+vr/+/v7//z8/P/9/f3//v7+//////8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/NCYmJiYmJiYmJiYmJiYmNCZKSkpKSkpKSkpKSkpKSiYmSkpKRisdRkMbMklKSkomJkpKSSEiNUhEEQwpSUpKJiZKSi8LHhhAPAwBDDZKSiYmSkoWACA7SEc6HAEaSkomJkpKBxI/SkpKSj4ICkpKJiZKSgUTR0pKSkpGDwZKSiYmSkoTED1KSkpKOQQVSkomJkpKKgowMy4sNycIMUpKJiZKSkEZDgkDAgsNH0VKSiYmSkpKQigUBgkXLUhKSkomJkpKSkpKSkpKSkpKSkpKJiYmJiYmJiYmJiYmJiYmJiYmIyUkNDQ0NDQ0NDQ0NDQmOCYmJiYmJiYmJiYmJiYmOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" / >
< link rel = "stylesheet" href = "/__/grip/static/octicons/octicons.css" / >
< style >
2022-03-25 04:01:40 +00:00
/*!
* GitHub Light v0.4.1
2020-01-28 05:02:07 +00:00
* Copyright (c) 2012 - 2017 GitHub, Inc.
* Licensed under MIT (https://github.com/primer/github-syntax-theme-generator/blob/master/LICENSE)
2022-03-25 04:01:40 +00:00
*/.pl-c{color:#6a737d}.pl-c1,.pl-s .pl-v{color:#005cc5}.pl-e,.pl-en{color:#6f42c1}.pl-smi,.pl-s .pl-s1{color:#24292e}.pl-ent{color:#22863a}.pl-k{color:#d73a49}.pl-s,.pl-pds,.pl-s .pl-pse .pl-s1,.pl-sr,.pl-sr .pl-cce,.pl-sr .pl-sre,.pl-sr .pl-sra{color:#032f62}.pl-v,.pl-smw{color:#e36209}.pl-bu{color:#b31d28}.pl-ii{color:#fafbfc;background-color:#b31d28}.pl-c2{color:#fafbfc;background-color:#d73a49}.pl-c2::before{content:"^M"}.pl-sr .pl-cce{font-weight:bold;color:#22863a}.pl-ml{color:#735c0f}.pl-mh,.pl-mh .pl-en,.pl-ms{font-weight:bold;color:#005cc5}.pl-mi{font-style:italic;color:#24292e}.pl-mb{font-weight:bold;color:#24292e}.pl-md{color:#b31d28;background-color:#ffeef0}.pl-mi1{color:#22863a;background-color:#f0fff4}.pl-mc{color:#e36209;background-color:#ffebda}.pl-mi2{color:#f6f8fa;background-color:#005cc5}.pl-mdr{font-weight:bold;color:#6f42c1}.pl-ba{color:#586069}.pl-sg{color:#959da5}.pl-corl{text-decoration:underline;color:#032f62}.CodeMirror{font-family:monospace;height:300px;color:black;direction:ltr}.CodeMirror-lines{padding:4px 0}.CodeMirror pre{padding:0 4px}.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{background-color:white}.CodeMirror-gutters{border-right:1px solid #ddd;background-color:#f7f7f7;white-space:nowrap}.CodeMirror-linenumber{padding:0 3px 0 5px;min-width:20px;text-align:right;color:#999;white-space:nowrap}.CodeMirror-guttermarker{color:black}.CodeMirror-guttermarker-subtle{color:#999}.CodeMirror-cursor{border-left:1px solid black;border-right:none;width:0}.CodeMirror div.CodeMirror-secondarycursor{border-left:1px solid silver}.cm-fat-cursor .CodeMirror-cursor{width:auto;border:0 !important;background:#7e7}.cm-fat-cursor div.CodeMirror-cursors{z-index:1}.cm-fat-cursor-mark{background-color:rgba(20,255,20,0.5);animation:blink 1.06s steps(1) infinite}.cm-animate-fat-cursor{width:auto;border:0;animation:blink 1.06s steps(1) infinite;background-color:#7e7}@keyframes blink{0%{}50%{background-color:transparent}100%{}}.cm-tab{display:inline-block;text-decoration:inherit}.CodeMirror-rulers{position:absolute;left:0;right:0;top:-50px;bottom:-20px;overflow:hidden}.CodeMirror-ruler{border-left:1px solid #ccc;top:0;bottom:0;position:absolute}.cm-s-default .cm-header{color:blue}.cm-s-default .cm-quote{color:#090}.cm-negative{color:#d44}.cm-positive{color:#292}.cm-header,.cm-strong{font-weight:bold}.cm-em{font-style:italic}.cm-link{text-decoration:underline}.cm-strikethrough{text-decoration:line-through}.cm-s-default .cm-keyword{color:#708}.cm-s-default .cm-atom{color:#219}.cm-s-default .cm-number{color:#164}.cm-s-default .cm-def{color:#00f}.cm-s-default .cm-variable-2{color:#05a}.cm-s-default .cm-variable-3,.cm-s-default .cm-type{color:#085}.cm-s-default .cm-comment{color:#a50}.cm-s-default .cm-string{color:#a11}.cm-s-default .cm-string-2{color:#f50}.cm-s-default .cm-meta{color:#555}.cm-s-default .cm-qualifier{color:#555}.cm-s-default .cm-builtin{color:#30a}.cm-s-default .cm-bracket{color:#997}.cm-s-default .cm-tag{color:#170}.cm-s-default .cm-attribute{color:#00c}.cm-s-default .cm-hr{color:#999}.cm-s-default .cm-link{color:#00c}.cm-s-default .cm-error{color:#f00}.cm-invalidchar{color:#f00}.CodeMirror-composing{border-bottom:2px solid}div.CodeMirror span.CodeMirror-matchingbracket{color:#0b0}div.CodeMirror span.CodeMirror-nonmatchingbracket{color:#a22}.CodeMirror-matchingtag{background:rgba(255,150,0,0.3)}.CodeMirror-activeline-background{background:#e8f2ff}.CodeMirror{position:relative;overflow:hidden;background:white}.CodeMirror-scroll{overflow:scroll !important;margin-bottom:-30px;margin-right:-30px;padding-bottom:30px;height:100%;outline:none;position:relative}.CodeMirror-sizer{position:relative;border-right:30px solid transparent}.CodeMirror-vscrollbar,.CodeMirror-hscrollbar,.CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler{position:absolute;z-index:6;display:none}.CodeMirror-vscrollbar{right:0;top:0;overflow-x:hidden;overflow-y:scroll}.CodeMirror-hscrollbar{bottom:0;left:0;overflow-y:hidden;overflow-x:scroll}.CodeMirror-scrollbar-filler{right:0;bottom:0}.CodeMirror-gutter-filler{left:0;bottom
2020-01-28 05:02:07 +00:00
* GitHub Light v0.4.2
* Copyright (c) 2012 - 2017 GitHub, Inc.
* Licensed under MIT (https://github.com/primer/github-syntax-theme-generator/blob/master/LICENSE)
2022-03-25 04:01:40 +00:00
*/.cm-s-github-light.CodeMirror{background:#fff;color:#24292e}.cm-s-github-light .CodeMirror-gutters{background:#fff;border-right-width:0}.cm-s-github-light .CodeMirror-guttermarker{color:white}.cm-s-github-light .CodeMirror-guttermarker-subtle{color:#d0d0d0}.cm-s-github-light .CodeMirror-linenumber{color:#959da5;padding:0 16px 0 16px}.cm-s-github-light .CodeMirror-cursor{border-left:1px solid #24292e}.cm-s-github-light div.CodeMirror-selected,.cm-s-github-light .CodeMirror-line::-moz-selection,.cm-s-github-light .CodeMirror-line>span::-moz-selection,.cm-s-github-light .CodeMirror-line>span>span::-moz-selection,.cm-s-github-light .CodeMirror-line::-moz-selection,.cm-s-github-light .CodeMirror-line>span::-moz-selection,.cm-s-github-light .CodeMirror-line>span>span::-moz-selection{background:#c8c8fa}.cm-s-github-light div.CodeMirror-selected,.cm-s-github-light .CodeMirror-line::selection,.cm-s-github-light .CodeMirror-line>span::selection,.cm-s-github-light .CodeMirror-line>span>span::selection,.cm-s-github-light .CodeMirror-line::-moz-selection,.cm-s-github-light .CodeMirror-line>span::-moz-selection,.cm-s-github-light .CodeMirror-line>span>span::-moz-selection{background:#c8c8fa}.cm-s-github-light .CodeMirror-activeline-background{background:#fafbfc}.cm-s-github-light .CodeMirror-matchingbracket{text-decoration:underline;color:#24292e !important}.cm-s-github-light .CodeMirror-lines{font-family:"SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;font-size:12px;background:#fff;line-height:1.5}.cm-s-github-light .cm-comment{color:#6a737d}.cm-s-github-light .cm-constant{color:#005cc5}.cm-s-github-light .cm-entity{font-weight:normal;font-style:normal;text-decoration:none;color:#6f42c1}.cm-s-github-light .cm-keyword{font-weight:normal;font-style:normal;text-decoration:none;color:#d73a49}.cm-s-github-light .cm-storage{color:#d73a49}.cm-s-github-light .cm-string{font-weight:normal;font-style:normal;text-decoration:none;color:#032f62}.cm-s-github-light .cm-support{font-weight:normal;font-style:normal;text-decoration:none;color:#005cc5}.cm-s-github-light .cm-variable{font-weight:normal;font-style:normal;text-decoration:none;color:#e36209}details-dialog{position:fixed;margin:10vh auto;top:0;left:50%;transform:translateX(-50%);z-index:999;max-height:80vh;max-width:90vw;width:448px}.octicon{display:inline-block;vertical-align:text-top;fill:currentColor}body.intent-mouse [role="button"]:focus,body.intent-mouse button:focus,body.intent-mouse summary:focus{outline:none}.CodeMirror{height:calc(100vh - 1px)}.file-editor-textarea{width:100%;padding:5px 4px;font:12px "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;resize:vertical;border:0;border-radius:0;outline:none}.container-preview .tabnav-tabs{margin:-6px 0 -6px -11px}.container-preview .tabnav-tabs .tabnav-tab{padding:12px 15px;border-radius:0}.container-preview .tabnav-tabs>.selected:first-child{border-top-left-radius:3px}.container-preview .tabnav-tabs .selected{font-weight:600}.container-preview.template-editor .commit-create,.container-preview.template-editor .file-actions{display:block}.container-preview.template-editor .show-code,.container-preview.template-editor .commit-preview,.container-preview.template-editor .loading-preview-msg,.container-preview.template-editor .no-changes-preview-msg,.container-preview.template-editor .error-preview-msg{display:none}.container-preview.render-editor .commit-create,.container-preview.render-editor .file-actions{display:block}.container-preview.render-editor .template-editor,.container-preview.render-editor .show-code,.container-preview.render-editor .commit-preview,.container-preview.render-editor .loading-preview-msg,.container-preview.render-editor .no-changes-preview-msg,.container-preview.render-editor .error-preview-msg{display:none}.container-preview.show-code .commit-create,.container-preview.show-code .file-actions{display:block}.container-preview.show-code .template-editor,.container-preview.show-code .render-editor,.container-preview.show-code .commit-preview,.container-preview.show-cod
* Primer-core
* http://primer.github.io
*
* Released under MIT license. Copyright (c) 2018 GitHub Inc.
*//*! normalize.css v4.1.1 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,main,menu,nav,section{display:block}summary{display:list-item}audio,canvas,progress,video{display:inline-block}audio:not([controls]){display:none;height:0}progress{vertical-align:baseline}template,[hidden]{display:none}a{background-color:transparent}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:inherit}b,strong{font-weight:bolder}dfn{font-style:italic}h1{font-size:2em;margin:0.67em 0}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}svg:not(:root){overflow:hidden}code,kbd,pre,samp{font-family:monospace, monospace;font-size:1em}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}button,input,select,textarea{font:inherit;margin:0}optgroup{font-weight:bold}button,input{overflow:visible}button,select{text-transform:none}button,html [type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-cancel-button,[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-input-placeholder{color:inherit;opacity:0.54}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}*{box-sizing:border-box}input,select,textarea,button{font-family:inherit;font-size:inherit;line-height:inherit}body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:14px;line-height:1.5;color:#24292e;background-color:#fff}a{color:#0366d6;text-decoration:none}a:hover{text-decoration:underline}b,strong{font-weight:600}hr,.rule{height:0;margin:15px 0;overflow:hidden;background:transparent;border:0;border-bottom:1px solid #dfe2e5}hr::before,.rule::before{display:table;content:""}hr::after,.rule::after{display:table;clear:both;content:""}table{border-spacing:0;border-collapse:collapse}td,th{padding:0}button{cursor:pointer;border-radius:0}details summary{cursor:pointer}details:not([open])>*:not(summary){display:none !important}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:0}h1{font-size:32px;font-weight:600}h2{font-size:24px;font-weight:600}h3{font-size:20px;font-weight:600}h4{font-size:16px;font-weight:600}h5{font-size:14px;font-weight:600}h6{font-size:12px;font-weight:600}p{margin-top:0;margin-bottom:10px}small{font-size:90%}blockquote{margin:0}ul,ol{padding-left:0;margin-top:0;margin-bottom:0}ol ol,ul ol{list-style-type:lower-roman}ul ul ol,ul ol ol,ol ul ol,ol ol ol{list-style-type:lower-alpha}dd{margin-left:0}tt,code{font-family:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px}pre{margin-top:0;margin-bottom:0;font-family:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px}.octicon{vertical-align:text-bottom}.Box{background-color:#fff;border:1px solid #d1d5da;border-radius:3px}.Box--condensed{line-height:1.25}.Box--condensed .Box-header{padding:8px 16px}.Box--condensed .Box-body{padding:8px 16px}.B
/*# sourceMappingURL=frameworks-afd119c67567f2c750f08c93d4211333.css.map */
2022-03-03 09:23:56 +00:00
2022-03-25 04:01:40 +00:00
/*!
* Primer-marketing
* http://primer.github.io
*
* Released under MIT license. Copyright (c) 2018 GitHub Inc.
*/.alt-mono-font{font-family:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace}.alt-h0,.alt-h1,.alt-h2,.alt-h3,.alt-h4,.alt-h5,.alt-h6,.alt-lead{-webkit-font-smoothing:antialiased;font-family:Roboto,-apple-system,BlinkMacSystemFont,"Helvetica Neue","Segoe UI","Oxygen","Ubuntu","Cantarell","Open Sans",sans-serif}.alt-h0{font-size:48px;font-weight:300}@media (min-width: 768px){.alt-h0{font-size:54px}}@media (min-width: 1012px){.alt-h0{font-size:72px}}.alt-h1{font-size:36px;font-weight:300}@media (min-width: 768px){.alt-h1{font-size:48px}}@media (min-width: 1012px){.alt-h1{font-size:54px}}.alt-h2{font-size:28px;font-weight:300}@media (min-width: 768px){.alt-h2{font-size:34px}}@media (min-width: 1012px){.alt-h2{font-size:38px}}.alt-h3{font-size:18px;font-weight:400}@media (min-width: 768px){.alt-h3{font-size:20px}}@media (min-width: 1012px){.alt-h3{font-size:22px}}.alt-h4{font-size:16px;font-weight:500}.alt-h5{font-size:14px;font-weight:500}.alt-h6{font-size:12px;font-weight:500}.alt-lead{-webkit-font-smoothing:antialiased;font-size:21px;font-weight:300}@media (min-width: 768px){.alt-lead{font-size:24px}}@media (min-width: 1012px){.alt-lead{font-size:26px}}.alt-text-small{font-size:14px !important}.pullquote{padding-top:0;padding-bottom:0;padding-left:8px;margin-bottom:24px;font-family:"SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:16px;line-height:1.4;color:#586069;border-left:3px solid #e1e4e8}@media (min-width: 768px){.pullquote{padding-left:12px;margin-bottom:32px;margin-left:-15px;font-size:18px;line-height:1.5}}.btn-orange{color:#fff;background-color:#d25a08;background-image:linear-gradient(-180deg, #f7802f 0%, #d25a08 90%)}.btn-orange:focus,.btn-orange.focus{box-shadow:0 0 0 0.2em rgba(247,128,47,0.4)}.btn-orange:hover,.btn-orange.hover{background-color:#c85607;background-image:linear-gradient(-180deg, #f77a25 0%, #c85607 90%);background-position:-.5em;border-color:rgba(27,31,35,0.5)}.btn-orange:active,.btn-orange.selected,[open]>.btn-orange{background-color:#c65e17;background-image:none;border-color:rgba(27,31,35,0.5);box-shadow:inset 0 0.15em 0.3em rgba(27,31,35,0.15)}.btn-orange:disabled,.btn-orange.disabled{color:rgba(255,255,255,0.75);background-color:#e9ad83;background-image:none;border-color:rgba(27,31,35,0.2);box-shadow:none}.btn-orange .Counter{color:#f46909;background-color:#fff}.btn-outline-purple{color:#6f42c1;background-color:#fff;background-image:none}.btn-outline-purple .Counter{background-color:rgba(27,31,35,0.07)}.btn-outline-purple:hover,.btn-outline-purple:active,.btn-outline-purple.selected,[open]>.btn-outline-purple{color:#fff;background-color:#6f42c1;background-image:none;border-color:#6f42c1}.btn-outline-purple:hover .Counter,.btn-outline-purple:active .Counter,.btn-outline-purple.selected .Counter,[open]>.btn-outline-purple .Counter{color:#6f42c1;background-color:#fff}.btn-outline-purple:focus{border-color:#6f42c1;box-shadow:0 0 0 0.2em rgba(111,66,193,0.4)}.btn-outline-purple:disabled,.btn-outline-purple.disabled{color:rgba(27,31,35,0.3);background-color:#fff;border-color:rgba(27,31,35,0.15);box-shadow:none}.btn-outline-orange{color:#f66a0a;background-color:#fff;background-image:none}.btn-outline-orange .Counter{background-color:rgba(27,31,35,0.07)}.btn-outline-orange:hover,.btn-outline-orange:active,.btn-outline-orange.selected,[open]>.btn-outline-orange{color:#fff;background-color:#f66a0a;background-image:none;border-color:#f66a0a}.btn-outline-orange:hover .Counter,.btn-outline-orange:active .Counter,.btn-outline-orange.selected .Counter,[open]>.btn-outline-orange .Counter{color:#f66a0a;background-color:#fff}.btn-outline-orange:focus{border-color:#f66a0a;box-shadow:0 0 0 0.2em rgba(246,106,10,0.4)}.btn-outline-orange:disabled,.btn-outline-orange.disabled{color:rgba(27,31,35,0.3);background-color:#fff;border-color:rgba(27,31,35,0.15);box-shadow:none}.btn-outline-green{color:#28a745;background-color:#fff;background-image:none}.btn-outline-green .Counter{background-color:rgba(27,31,35,0.07)}.btn-outline-green:hover,.btn-outline-green:active,.bt
/*# sourceMappingURL=site-73680c8bae9d90e48e18affb463ea2cd.css.map */
2022-03-03 09:23:56 +00:00
2022-03-25 04:01:40 +00:00
/*!
* Primer-product
* http://primer.github.io
*
* Released under MIT license. Copyright (c) 2018 GitHub Inc.
*/.flash{position:relative;padding:16px;color:#032f62;background-color:#dbedff;border:1px solid rgba(27,31,35,0.15);border-radius:3px}.flash p:last-child{margin-bottom:0}.flash-messages{margin-bottom:24px}.flash-close{float:right;padding:16px;margin:-16px;color:inherit;text-align:center;cursor:pointer;background:none;border:0;-webkit-appearance:none;-moz-appearance:none;appearance:none;opacity:0.6}.flash-close:hover{opacity:1}.flash-action{float:right;margin-top:-3px;margin-left:24px}.flash-warn{color:#735c0f;background-color:#fffbdd;border-color:rgba(27,31,35,0.15)}.flash-error{color:#86181d;background-color:#ffdce0;border-color:rgba(27,31,35,0.15)}.flash-success{color:#165c26;background-color:#dcffe4;border-color:rgba(27,31,35,0.15)}.flash-full{margin-top:-1px;border-width:1px 0;border-radius:0}.warning{padding:.5em;margin-bottom:0.8em;font-weight:600;background-color:#fffbdd}.avatar{display:inline-block;overflow:hidden;line-height:1;vertical-align:middle;border-radius:3px}.avatar-small{border-radius:2px}.avatar-link{float:left;line-height:1}.avatar-group-item{display:inline-block;margin-bottom:3px}.avatar-parent-child{position:relative}.avatar-child{position:absolute;right:-15%;bottom:-9%;background-color:#fff;border-radius:2px;box-shadow:-2px -2px 0 rgba(255,255,255,0.8)}.avatar-stack{display:inline-block;white-space:nowrap}.avatar-stack .avatar{position:relative;z-index:2;display:inline-block;width:20px;height:20px;box-sizing:content-box;margin-right:-15px;background-color:#fff;border-right:1px solid #fff;border-radius:2px;transition:margin 0.1s ease-in-out}.avatar-stack .avatar:only-child{background-color:transparent}.avatar-stack .avatar:first-child{z-index:3}.avatar-stack .avatar:last-child{z-index:1;margin-right:0;border-right:0}.avatar-stack:hover .avatar{margin-right:3px}.avatar-stack:hover .avatar:last-child{margin-right:0}.AvatarStack{position:relative;min-width:26px;height:20px}.AvatarStack .AvatarStack-body{position:absolute}.AvatarStack.AvatarStack--two{min-width:36px}.AvatarStack.AvatarStack--three-plus{min-width:46px}.AvatarStack-body{display:flex;background:#fff}.AvatarStack-body .avatar{position:relative;z-index:2;display:flex;width:20px;height:20px;box-sizing:content-box;margin-right:-11px;background-color:#fff;border-right:1px solid #fff;border-radius:2px;transition:margin 0.1s ease-in-out}.AvatarStack-body .avatar:first-child{z-index:3}.AvatarStack-body .avatar:last-child{z-index:1;border-right:0}.AvatarStack-body .avatar img{border-radius:2px}.AvatarStack-body .avatar:nth-child(n+4){display:none;opacity:0}.AvatarStack-body:hover .avatar{margin-right:3px}.AvatarStack-body:hover .avatar:nth-child(n+4){display:flex;opacity:1}.AvatarStack-body:hover .avatar-more{display:none !important}.avatar.avatar-more{z-index:1;margin-right:0;background:#f6f8fa}.avatar.avatar-more::before,.avatar.avatar-more::after{position:absolute;display:block;height:20px;content:"";border-radius:2px;outline:1px solid #fff}.avatar.avatar-more::before{width:17px;background:#e1e4e8}.avatar.avatar-more::after{width:14px;background:#d1d5da}.AvatarStack--right .AvatarStack-body{right:0;flex-direction:row-reverse}.AvatarStack--right .AvatarStack-body:hover .avatar{margin-right:0;margin-left:3px}.AvatarStack--right .avatar.avatar-more{background:#d1d5da}.AvatarStack--right .avatar.avatar-more::before{width:5px}.AvatarStack--right .avatar.avatar-more::after{width:2px;background:#f6f8fa}.AvatarStack--right .avatar{margin-right:0;margin-left:-11px;border-right:0;border-left:1px solid #fff}.CircleBadge{display:flex;align-items:center;justify-content:center;background-color:#fff;border-radius:50%;box-shadow:0 1px 5px rgba(27,31,35,0.15)}.CircleBadge-icon{max-width:60% !important;height:auto !important;max-height:55% !important}.CircleBadge--small{width:56px;height:56px}.CircleBadge--medium{width:96px;height:96px}.CircleBadge--large{width:128px;height:128px}.DashedConnection{position:relative}.DashedConnection::before{position:absolute;top:50%;left:0;width:100%;content:"";border-bottom:2px dashed #e1e4e8}.DashedConnection .CircleBadge{pos
/*# sourceMappingURL=github-a12fe4c88979a8931d7e7adfee5656fc.css.map */
2020-01-28 05:02:07 +00:00
< / style >
< style >
/* Page tweaks */
.preview-page {
margin-top: 64px;
}
/* User-content tweaks */
.timeline-comment-wrapper > .timeline-comment:after,
.timeline-comment-wrapper > .timeline-comment:before {
content: none;
}
/* User-content overrides */
.discussion-timeline.wide {
width: 920px;
}
< / style >
< / head >
< body >
< div class = "page" >
< div id = "preview-page" class = "preview-page" data-autorefresh-url = "" >
2022-03-25 04:01:40 +00:00
< div role = "main" class = "main-content" >
< div class = "container new-discussion-timeline experiment-repo-nav" >
< div class = "repository-content" >
< div id = "readme" class = "readme boxed-group clearfix announce instapaper_body md" >
< h3 >
< span class = "octicon octicon-book" > < / span >
SheetJS Community Edition
< / h3 >
< article class = "markdown-body entry-content" itemprop = "text" id = "grip-content" >
< h1 >
2021-09-12 09:16:01 +00:00
< a id = "user-content-sheetjs" class = "anchor" href = "#sheetjs" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > < a href = "https://sheetjs.com" rel = "nofollow" > SheetJS< / a >
2020-01-28 05:02:07 +00:00
< / h1 >
2022-02-14 02:02:46 +00:00
< p > The SheetJS Community Edition offers battle-tested open-source solutions for
extracting useful data from almost any complex spreadsheet and generating new
spreadsheets that will work with legacy and modern software alike.< / p >
< p > < a href = "https://sheetjs.com/pro" rel = "nofollow" > SheetJS Pro< / a > offers solutions beyond data processing:
Edit complex templates with ease; let out your inner Picasso with styling; make
custom sheets with images/graphs/PivotTables; evaluate formula expressions and
port calculations to web apps; automate common spreadsheet tasks, and much more!< / p >
2022-02-01 06:12:44 +00:00
< p > < a href = "https://camo.githubusercontent.com/756bdb2076e17b3344ba27668018c9f0011b82a2a02f029790b3e3aa805154d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f53686565744a532f73686565746a73" target = "_blank" rel = "nofollow" > < img src = "https://camo.githubusercontent.com/756bdb2076e17b3344ba27668018c9f0011b82a2a02f029790b3e3aa805154d7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f53686565744a532f73686565746a73" alt = "License" data-canonical-src = "https://img.shields.io/github/license/SheetJS/sheetjs" style = "max-width:100%;" > < / a >
< a href = "https://github.com/SheetJS/sheetjs/actions" > < img src = "https://camo.githubusercontent.com/dba2780ce8f220a047aa004f096aa7b440ceee8afdb7a8b8f539e240e33673d5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f73686565746a732f73686565746a732f54657374733a2532306e6f64652e6a73" alt = "Build Status" data-canonical-src = "https://img.shields.io/github/workflow/status/sheetjs/sheetjs/Tests:%20node.js" style = "max-width:100%;" > < / a >
< a href = "https://snyk.io/test/github/SheetJS/sheetjs" rel = "nofollow" > < img src = "https://camo.githubusercontent.com/7ce09de464c75d8a533b9b2a156b487ab8db9f025f6ca9119395d894e82f69a7/68747470733a2f2f696d672e736869656c64732e696f2f736e796b2f76756c6e65726162696c69746965732f6769746875622f53686565744a532f73686565746a73" alt = "Snyk Vulnerabilities" data-canonical-src = "https://img.shields.io/snyk/vulnerabilities/github/SheetJS/sheetjs" style = "max-width:100%;" > < / a >
< a href = "https://npmjs.org/package/xlsx" rel = "nofollow" > < img src = "https://camo.githubusercontent.com/d271e8f58341837d08c59de862121e6faa608414d48b74fd12b88c507ee1bcdf/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f786c73782e737667" alt = "npm Downloads" data-canonical-src = "https://img.shields.io/npm/dm/xlsx.svg" style = "max-width:100%;" > < / a >
< a href = "https://github.com/SheetJS/sheetjs" > < img src = "https://camo.githubusercontent.com/5835ef9524626d64db0c7a60890d3723b178fb5ca8783250f405dd15dfc3b000/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d33363831303333332d312f53686565744a532f73686565746a733f706978656c" alt = "Analytics" data-canonical-src = "https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/sheetjs?pixel" style = "max-width:100%;" > < / a > < / p >
< p > < a href = "https://oss.sheetjs.com/sheetjs/tests/" rel = "nofollow" > < strong > Browser Test and Support Matrix< / strong > < / a > < / p >
< p > < a href = "https://saucelabs.com/u/sheetjs" rel = "nofollow" > < img src = "https://camo.githubusercontent.com/fd3943851066063e253cd05bc1a8b9436b80f841af7d193c3eacb560012acea6/68747470733a2f2f73617563656c6162732e636f6d2f62726f777365722d6d61747269782f73686565746a732e737667" alt = "Build Status" data-canonical-src = "https://saucelabs.com/browser-matrix/sheetjs.svg" style = "max-width:100%;" > < / a > < / p >
< p > < strong > Supported File Formats< / strong > < / p >
2020-01-28 05:02:07 +00:00
< p > < a href = "formats.png" target = "_blank" rel = "noopener noreferrer" > < img src = "formats.png" alt = "circo graph of format support" style = "max-width:100%;" > < / a > < / p >
< p > < a href = "legend.png" target = "_blank" rel = "noopener noreferrer" > < img src = "legend.png" alt = "graph legend" style = "max-width:100%;" > < / a > < / p >
< h2 >
< a id = "user-content-table-of-contents" class = "anchor" href = "#table-of-contents" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Table of Contents< / h2 >
< details >
< summary > < b > Expand to show Table of Contents< / b > < / summary >
< ul >
< li >
2022-02-14 02:02:46 +00:00
< a href = "#getting-started" > Getting Started< / a >
2020-01-28 05:02:07 +00:00
< ul >
2022-05-11 21:03:03 +00:00
< li >
< a href = "#installation" > Installation< / a >
< ul >
< li > < a href = "#standalone-browser-scripts" > Standalone Browser Scripts< / a > < / li >
< li > < a href = "#ecmascript-modules" > ECMAScript Modules< / a > < / li >
< li > < a href = "#deno" > Deno< / a > < / li >
< li > < a href = "#nodejs" > NodeJS< / a > < / li >
< li > < a href = "#photoshop-and-indesign" > Photoshop and InDesign< / a > < / li >
< / ul >
< / li >
2022-02-14 02:02:46 +00:00
< li > < a href = "#usage" > Usage< / a > < / li >
< li > < a href = "#the-zen-of-sheetjs" > The Zen of SheetJS< / a > < / li >
2020-01-28 05:02:07 +00:00
< li > < a href = "#js-ecosystem-demos" > JS Ecosystem Demos< / a > < / li >
< / ul >
< / li >
< li >
2022-02-14 02:02:46 +00:00
< a href = "#acquiring-and-extracting-data" > Acquiring and Extracting Data< / a >
2020-01-28 05:02:07 +00:00
< ul >
2022-02-14 02:02:46 +00:00
< li > < a href = "#parsing-workbooks" > Parsing Workbooks< / a > < / li >
< li > < a href = "#processing-json-and-js-data" > Processing JSON and JS Data< / a > < / li >
< li > < a href = "#processing-html-tables" > Processing HTML Tables< / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< / li >
< li >
2022-03-03 09:23:56 +00:00
< a href = "#processing-data" > Processing Data< / a >
2020-01-28 05:02:07 +00:00
< ul >
2022-03-03 09:23:56 +00:00
< li > < a href = "#modifying-workbook-structure" > Modifying Workbook Structure< / a > < / li >
< li > < a href = "#modifying-cell-values" > Modifying Cell Values< / a > < / li >
< li > < a href = "#modifying-other-worksheet--workbook--cell-properties" > Modifying Other Worksheet / Workbook / Cell Properties< / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< / li >
< li >
2022-02-14 02:02:46 +00:00
< a href = "#packaging-and-releasing-data" > Packaging and Releasing Data< / a >
2020-01-28 05:02:07 +00:00
< ul >
2022-02-14 02:02:46 +00:00
< li > < a href = "#writing-workbooks" > Writing Workbooks< / a > < / li >
2020-01-28 05:02:07 +00:00
< li > < a href = "#writing-examples" > Writing Examples< / a > < / li >
< li > < a href = "#streaming-write" > Streaming Write< / a > < / li >
2022-02-14 02:02:46 +00:00
< li > < a href = "#generating-json-and-js-data" > Generating JSON and JS Data< / a > < / li >
< li > < a href = "#generating-html-tables" > Generating HTML Tables< / a > < / li >
2022-03-03 09:23:56 +00:00
< li > < a href = "#generating-single-worksheet-snapshots" > Generating Single-Worksheet Snapshots< / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< / li >
< li >
< a href = "#interface" > Interface< / a >
< ul >
< li > < a href = "#parsing-functions" > Parsing functions< / a > < / li >
< li > < a href = "#writing-functions" > Writing functions< / a > < / li >
< li > < a href = "#utilities" > Utilities< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#common-spreadsheet-format" > Common Spreadsheet Format< / a >
< ul >
< li > < a href = "#general-structures" > General Structures< / a > < / li >
< li >
< a href = "#cell-object" > Cell Object< / a >
< ul >
< li > < a href = "#data-types" > Data Types< / a > < / li >
< li > < a href = "#dates" > Dates< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#sheet-objects" > Sheet Objects< / a >
< ul >
< li > < a href = "#worksheet-object" > Worksheet Object< / a > < / li >
< li > < a href = "#chartsheet-object" > Chartsheet Object< / a > < / li >
< li > < a href = "#macrosheet-object" > Macrosheet Object< / a > < / li >
< li > < a href = "#dialogsheet-object" > Dialogsheet Object< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#workbook-object" > Workbook Object< / a >
< ul >
< li > < a href = "#workbook-file-properties" > Workbook File Properties< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#workbook-level-attributes" > Workbook-Level Attributes< / a >
< ul >
< li > < a href = "#defined-names" > Defined Names< / a > < / li >
< li > < a href = "#workbook-views" > Workbook Views< / a > < / li >
< li > < a href = "#miscellaneous-workbook-properties" > Miscellaneous Workbook Properties< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#document-features" > Document Features< / a >
< ul >
< li > < a href = "#formulae" > Formulae< / a > < / li >
2022-02-14 02:02:46 +00:00
< li > < a href = "#row-and-column-properties" > Row and Column Properties< / a > < / li >
2020-01-28 05:02:07 +00:00
< li > < a href = "#number-formats" > Number Formats< / a > < / li >
< li > < a href = "#hyperlinks" > Hyperlinks< / a > < / li >
< li > < a href = "#cell-comments" > Cell Comments< / a > < / li >
< li > < a href = "#sheet-visibility" > Sheet Visibility< / a > < / li >
< li > < a href = "#vba-and-macros" > VBA and Macros< / a > < / li >
< / ul >
< / li >
< / ul >
< / li >
< li >
< a href = "#parsing-options" > Parsing Options< / a >
< ul >
< li > < a href = "#input-type" > Input Type< / a > < / li >
< li > < a href = "#guessing-file-type" > Guessing File Type< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#writing-options" > Writing Options< / a >
< ul >
< li > < a href = "#supported-output-formats" > Supported Output Formats< / a > < / li >
< li > < a href = "#output-type" > Output Type< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#utility-functions" > Utility Functions< / a >
< ul >
< li > < a href = "#array-of-arrays-input" > Array of Arrays Input< / a > < / li >
< li > < a href = "#array-of-objects-input" > Array of Objects Input< / a > < / li >
< li > < a href = "#html-table-input" > HTML Table Input < / a > < / li >
< li > < a href = "#formulae-output" > Formulae Output< / a > < / li >
< li >
< a href = "#delimiter-separated-output" > Delimiter-Separated Output< / a >
< ul >
< li > < a href = "#utf-16-unicode-text" > UTF-16 Unicode Text< / a > < / li >
< / ul >
< / li >
< li > < a href = "#html-output" > HTML Output< / a > < / li >
< li > < a href = "#json" > JSON< / a > < / li >
< / ul >
< / li >
2022-02-14 02:02:46 +00:00
< li > < a href = "#file-formats" > File Formats< / a > < / li >
2020-01-28 05:02:07 +00:00
< li >
< a href = "#testing" > Testing< / a >
< ul >
< li > < a href = "#node" > Node< / a > < / li >
< li > < a href = "#browser" > Browser< / a > < / li >
< li > < a href = "#tested-environments" > Tested Environments< / a > < / li >
< li > < a href = "#test-files" > Test Files< / a > < / li >
< / ul >
< / li >
< li >
< a href = "#contributing" > Contributing< / a >
< ul >
< li > < a href = "#osxlinux" > OSX/Linux< / a > < / li >
< li > < a href = "#windows" > Windows< / a > < / li >
< li > < a href = "#tests" > Tests< / a > < / li >
< / ul >
< / li >
< li > < a href = "#license" > License< / a > < / li >
< li > < a href = "#references" > References< / a > < / li >
< / ul >
< / details >
< h2 >
2022-02-14 02:02:46 +00:00
< a id = "user-content-getting-started" class = "anchor" href = "#getting-started" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Getting Started< / h2 >
< h3 >
< a id = "user-content-installation" class = "anchor" href = "#installation" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Installation< / h3 >
2022-05-11 21:03:03 +00:00
< h4 >
< a id = "user-content-standalone-browser-scripts" class = "anchor" href = "#standalone-browser-scripts" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Standalone Browser Scripts< / h4 >
< p > Each standalone release script is available at < a href = "https://cdn.sheetjs.com/" rel = "nofollow" > https://cdn.sheetjs.com/< / a > .< / p >
< p > The current version is < code > 0.18.7< / code > and can be referenced as follows:< / p >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-c" > < !-- use version 0.18.7 --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > lang< / span > ="< span class = "pl-s" > javascript< / span > " < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< p > The < code > latest< / code > tag references the latest version and updates with each release:< / p >
2022-04-14 17:50:18 +00:00
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-c" > < !-- use the latest version --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > lang< / span > ="< span class = "pl-s" > javascript< / span > " < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< p > < strong > For production use, scripts should be downloaded and added to a public folder
alongside other scripts.< / strong > < / p >
2022-02-14 02:02:46 +00:00
< details >
< summary > < b > Browser builds< / b > (click to show)< / summary >
< p > The complete single-file version is generated at < code > dist/xlsx.full.min.js< / code > < / p >
2022-03-03 09:23:56 +00:00
< p > < code > dist/xlsx.core.min.js< / code > omits codepage library (no support for XLS encodings)< / p >
2022-02-14 02:02:46 +00:00
< p > A slimmer build is generated at < code > dist/xlsx.mini.min.js< / code > . Compared to full build:< / p >
< ul >
< li > codepage library skipped (no support for XLS encodings)< / li >
2022-03-03 09:23:56 +00:00
< li > no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003 / Numbers< / li >
2022-02-14 02:02:46 +00:00
< li > node stream utils removed< / li >
< / ul >
2022-04-14 17:50:18 +00:00
< p > These scripts are also available on the CDN:< / p >
2022-05-11 21:03:03 +00:00
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-c" > < !-- use xlsx.mini.min.js from version 0.18.7 --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > lang< / span > ="< span class = "pl-s" > javascript< / span > " < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/xlsx.mini.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< / details >
< p > < a href = "https://bower.io/" rel = "nofollow" > Bower< / a > plays nice with the CDN tarballs:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ npx bower install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz< / pre > < / div >
< p > Bower will place the standalone scripts in < code > bower_components/js-xlsx/dist/< / code > < / p >
< details >
< summary > < b > Internet Explorer and ECMAScript 3 Compatibility< / b > (click to show)< / summary >
< p > For broad compatibility with JavaScript engines, the library is written using
ECMAScript 3 language dialect as well as some ES5 features like < code > Array#forEach< / code > .
Older browsers require shims to provide missing functions.< / p >
< p > To use the shim, add the shim before the script tag that loads < code > xlsx.js< / code > :< / p >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-c" > < !-- add the shim first --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > text/javascript< / span > " < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > shim.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-c" > < !-- after the shim is referenced, add the library --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > text/javascript< / span > " < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< p > Due to SSL certificate compatibility issues, it is highly recommended to save
the Standalone and Shim scripts from < a href = "https://cdn.sheetjs.com/" rel = "nofollow" > https://cdn.sheetjs.com/< / a > and add to a
public directory in the site.< / p >
< p > The script also includes < code > IE_LoadFile< / code > and < code > IE_SaveFile< / code > for loading and saving
files in Internet Explorer versions 6-9. The < code > xlsx.extendscript.js< / code > script
bundles the shim in a format suitable for Photoshop and other Adobe products.< / p >
2022-02-14 02:02:46 +00:00
< / details >
2022-05-11 21:03:03 +00:00
< h4 >
< a id = "user-content-ecmascript-modules" class = "anchor" href = "#ecmascript-modules" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > ECMAScript Modules< / h4 >
< p > < em > Browser ESM< / em > < / p >
2022-02-14 02:02:46 +00:00
< p > The ECMAScript Module build is saved to < code > xlsx.mjs< / code > and can be directly added to
2022-04-14 17:50:18 +00:00
a page with a < code > script< / code > tag using < code > type="module"< / code > :< / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > module< / span > "< span class = "pl-kos" > > < / span >
2022-05-11 21:03:03 +00:00
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > read< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > writeFileXLSX< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "https://cdn.sheetjs.com/xlsx-0.18.7/package/xlsx.mjs"< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* load the codepage support library for extended support with older formats */< / span >
2022-05-11 21:03:03 +00:00
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > set_cptable< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "https://cdn.sheetjs.com/xlsx-0.18.7/package/xlsx.mjs"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/cpexcel.full.mjs'< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-en" > set_cptable< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< p > < em > Frameworks (Angular, VueJS, React) and Bundlers (webpack, etc)< / em > < / p >
< p > The NodeJS package is readily installed from the tarballs:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ npm install --save https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > npm< / span >
$ pnpm install --save https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > pnpm< / span >
$ yarn add --save https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > yarn< / span > < / pre > < / div >
< p > Once installed, the library can be imported under the name < code > xlsx< / code > :< / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > read< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > writeFileXLSX< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* load the codepage support library for extended support with older formats */< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > set_cptable< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'xlsx/dist/cpexcel.full.mjs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-en" > set_cptable< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< h4 >
< a id = "user-content-deno" class = "anchor" href = "#deno" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Deno< / h4 >
2022-04-14 17:50:18 +00:00
< p > < code > xlsx.mjs< / code > can be imported in Deno:< / p >
2022-05-11 21:03:03 +00:00
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-c" > // < span class = "pl-k" > @deno< / span > -types="https://cdn.sheetjs.com/xlsx-0.18.7/package/types/index.d.ts"< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-smi" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'https://cdn.sheetjs.com/xlsx-0.18.7/package/xlsx.mjs'< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* load the codepage support library for extended support with older formats */< / span >
2022-05-11 21:03:03 +00:00
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/cpexcel.full.mjs'< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-smi" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > set_cptable< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > cptable< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< h4 >
< a id = "user-content-nodejs" class = "anchor" href = "#nodejs" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > NodeJS< / h4 >
2022-04-14 17:50:18 +00:00
< p > Tarballs are available on < a href = "https://cdn.sheetjs.com" rel = "nofollow" > https://cdn.sheetjs.com< / a > .< / p >
2022-05-11 21:03:03 +00:00
< p > Each individual version can be referenced using a similar URL pattern.
< a href = "https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz" rel = "nofollow" > https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz< / a > is the URL for < code > 0.18.7< / code > < / p >
2022-04-14 17:50:18 +00:00
< p > < a href = "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz" rel = "nofollow" > https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz< / a > is a link to the latest
version and will refresh on each release.< / p >
2022-05-11 21:03:03 +00:00
< p > < em > Installation< / em > < / p >
< p > Tarballs can be directly installed using a package manager:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ npm install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > npm< / span >
$ pnpm install https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > pnpm< / span >
$ yarn add https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > yarn< / span > < / pre > < / div >
2022-04-14 17:50:18 +00:00
< p > For general stability, "vendoring" modules is the recommended approach:< / p >
< ol >
< li >
2022-05-11 21:03:03 +00:00
< p > Download the tarball (< code > xlsx-0.18.7.tgz< / code > ) for the desired version. The current
version is available at < a href = "https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz" rel = "nofollow" > https://cdn.sheetjs.com/xlsx-0.18.7/xlsx-0.18.7.tgz< / a > < / p >
2022-04-14 17:50:18 +00:00
< / li >
< li >
< p > Create a < code > vendor< / code > subdirectory at the root of your project and move the
tarball to that folder. Add it to your project repository.< / p >
< / li >
< li >
< p > Install the tarball using a package manager:< / p >
< / li >
< / ol >
2022-05-11 21:03:03 +00:00
< div class = "highlight highlight-source-shell" > < pre > $ npm install --save file:vendor/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > npm< / span >
$ pnpm install --save file:vendor/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > pnpm< / span >
$ yarn add file:vendor/xlsx-0.18.7.tgz < span class = "pl-c" > < span class = "pl-c" > #< / span > yarn< / span > < / pre > < / div >
2022-04-14 17:50:18 +00:00
< p > The package will be installed and accessible as < code > xlsx< / code > .< / p >
2022-05-11 21:03:03 +00:00
< p > < em > Usage< / em > < / p >
< p > By default, the module supports < code > require< / code > and it will automatically add support
for streams and filesystem access:< / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< p > The module also ships with < code > xlsx.mjs< / code > for use with < code > import< / code > . The < code > mjs< / code > version
does not automatically load native node modules:< / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'xlsx/xlsx.mjs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* load 'fs' for readFile and writeFile support */< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'fs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > set_fs< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-03-25 04:01:40 +00:00
< span class = "pl-c" > /* load 'stream' for stream support */< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-v" > Readable< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'stream'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > set_readable< / span > < span class = "pl-kos" > (< / span > < span class = "pl-v" > Readable< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* load the codepage support library for extended support with older formats */< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-s1" > cpexcel< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'xlsx/dist/cpexcel.full.mjs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > set_cptable< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > cpexcel< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-05-11 21:03:03 +00:00
< h4 >
< a id = "user-content-photoshop-and-indesign" class = "anchor" href = "#photoshop-and-indesign" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Photoshop and InDesign< / h4 >
2022-04-14 17:50:18 +00:00
< p > < code > dist/xlsx.extendscript.js< / code > is an ExtendScript build for Photoshop and InDesign.
2022-05-11 21:03:03 +00:00
< a href = "https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/xlsx.extendscript.js" rel = "nofollow" > https://cdn.sheetjs.com/xlsx-0.18.7/package/dist/xlsx.extendscript.js< / a > is the
current version. After downloading the script, it can be directly referenced
with a < code > #include< / code > directive:< / p >
2022-02-14 02:02:46 +00:00
< pre lang = "extendscript" > < code > #include "xlsx.extendscript.js"
< / code > < / pre >
< h3 >
< a id = "user-content-usage" class = "anchor" href = "#usage" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Usage< / h3 >
< p > Most scenarios involving spreadsheets and data can be broken into 5 parts:< / p >
< ol >
< li >
< p > < strong > Acquire Data< / strong > : Data may be stored anywhere: local or remote files,
databases, HTML TABLE, or even generated programmatically in the web browser.< / p >
< / li >
< li >
< p > < strong > Extract Data< / strong > : For spreadsheet files, this involves parsing raw bytes to
read the cell data. For general JS data, this involves reshaping the data.< / p >
< / li >
< li >
< p > < strong > Process Data< / strong > : From generating summary statistics to cleaning data
records, this step is the heart of the problem.< / p >
< / li >
< li >
< p > < strong > Package Data< / strong > : This can involve making a new spreadsheet or serializing
with < code > JSON.stringify< / code > or writing XML or simply flattening data for UI tools.< / p >
< / li >
< li >
< p > < strong > Release Data< / strong > : Spreadsheet files can be uploaded to a server or written
locally. Data can be presented to users in an HTML TABLE or data grid.< / p >
< / li >
< / ol >
< p > A common problem involves generating a valid spreadsheet export from data stored
in an HTML table. In this example, an HTML TABLE on the page will be scraped,
a row will be added to the bottom with the date of the report, and a new file
will be generated and downloaded locally. < code > XLSX.writeFile< / code > takes care of
packaging the data and attempting a local download:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // Acquire Data (reference to the HTML table)< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > table_elt< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "my-table-id"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // Extract Data (create a workbook object from the table)< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_book< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > table_elt< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // Process Data (add a new row)< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Created "< / span > < span class = "pl-c1" > +< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > Date< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > toISOString< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > :< span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // Package and Release Data (`writeFile` tries to write and save an XLSB file)< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Report.xlsb"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > This library tries to simplify steps 2 and 4 with functions to extract useful
data from spreadsheet files (< code > read< / code > / < code > readFile< / code > ) and generate new spreadsheet
files from data (< code > write< / code > / < code > writeFile< / code > ). Additional utility functions like
< code > table_to_book< / code > work with other common data sources like HTML tables.< / p >
< p > This documentation and various demo projects cover a number of common scenarios
and approaches for steps 1 and 5.< / p >
< p > Utility functions help with step 3.< / p >
2022-03-03 09:23:56 +00:00
< p > < a href = "#acquiring-and-extracting-data" > "Acquiring and Extracting Data"< / a > describes
solutions for common data import scenarios.< / p >
< p > < a href = "#packaging-and-releasing-data" > "Packaging and Releasing Data"< / a > describes
solutions for common data export scenarios.< / p >
< p > < a href = "#packaging-and-releasing-data" > "Processing Data"< / a > describes solutions for
common workbook processing and manipulation scenarios.< / p >
< p > < a href = "#utility-functions" > "Utility Functions"< / a > details utility functions for
translating JSON Arrays and other common JS structures into worksheet objects.< / p >
2022-02-14 02:02:46 +00:00
< h3 >
< a id = "user-content-the-zen-of-sheetjs" class = "anchor" href = "#the-zen-of-sheetjs" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > The Zen of SheetJS< / h3 >
< p > < em > Data processing should fit in any workflow< / em > < / p >
< p > The library does not impose a separate lifecycle. It fits nicely in websites
and apps built using any framework. The plain JS data objects play nice with
Web Workers and future APIs.< / p >
< p > < em > JavaScript is a powerful language for data processing< / em > < / p >
< p > The < a href = "#common-spreadsheet-format" > "Common Spreadsheet Format"< / a > is a simple object
representation of the core concepts of a workbook. The various functions in the
library provide low-level tools for working with the object.< / p >
< p > For friendly JS processing, there are utility functions for converting parts of
a worksheet to/from an Array of Arrays. The following example combines powerful
JS Array methods with a network request library to download data, select the
information we want and create a workbook file:< / p >
< details >
< summary > < b > Get Data from a JSON Endpoint and Generate a Workbook< / b > (click to show)< / summary >
< p > The goal is to generate a XLSB workbook of US President names and birthdays.< / p >
< p > < strong > Acquire Data< / strong > < / p >
< p > < em > Raw Data< / em > < / p >
< p > < a href = "https://theunitedstates.io/congress-legislators/executive.json" rel = "nofollow" > https://theunitedstates.io/congress-legislators/executive.json< / a > has the desired
data. For example, John Adams:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-kos" > {< / span >
< span class = "pl-s" > "id"< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c" > /* (data omitted) */< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-s" > "name"< / span > : < span class = "pl-kos" > {< / span >
< span class = "pl-s" > "first"< / span > : < span class = "pl-s" > "John"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- first name< / span >
< span class = "pl-s" > "last"< / span > : < span class = "pl-s" > "Adams"< / span > < span class = "pl-c" > // < -- last name< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-s" > "bio"< / span > : < span class = "pl-kos" > {< / span >
< span class = "pl-s" > "birthday"< / span > : < span class = "pl-s" > "1735-10-19"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- birthday< / span >
< span class = "pl-s" > "gender"< / span > : < span class = "pl-s" > "M"< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-s" > "terms"< / span > : < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-s" > "type"< / span > : < span class = "pl-s" > "viceprez"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > /* (other fields omitted) */< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-s" > "type"< / span > : < span class = "pl-s" > "viceprez"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > /* (other fields omitted) */< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-s" > "type"< / span > : < span class = "pl-s" > "prez"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > /* (other fields omitted) */< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c" > // < -- look for "prez"< / span >
< span class = "pl-kos" > ]< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
< p > < em > Filtering for Presidents< / em > < / p >
< p > The dataset includes Aaron Burr, a Vice President who was never President!< / p >
< p > < code > Array#filter< / code > creates a new array with the desired rows. A President served
at least one term with < code > type< / code > set to < code > "prez"< / code > . To test if a particular row has
at least one < code > "prez"< / code > term, < code > Array#some< / code > is another native JS function. The
complete filter would be:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-s1" > prez< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > raw_data< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > filter< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > row< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > terms< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > some< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > term< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > term< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > type< / span > < span class = "pl-c1" > ===< / span > < span class = "pl-s" > "prez"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Lining up the data< / em > < / p >
< p > For this example, the name will be the first name combined with the last name
(< code > row.name.first + " " + row.name.last< / code > ) and the birthday will be the subfield
< code > row.bio.birthday< / code > . Using < code > Array#map< / code > , the dataset can be massaged in one call:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > prez< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > row< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c1" > name< / span > : < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > first< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s" > " "< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > last< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > birthday< / span > : < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > bio< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > birthday< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The result is an array of "simple" objects with no nesting:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > name< / span > : < span class = "pl-s" > "George Washington"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > birthday< / span > : < span class = "pl-s" > "1732-02-22"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > name< / span > : < span class = "pl-s" > "John Adams"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > birthday< / span > : < span class = "pl-s" > "1735-10-19"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c" > // ... one row per President< / span >
< span class = "pl-kos" > ]< / span > < / pre > < / div >
< p > < strong > Extract Data< / strong > < / p >
< p > With the cleaned dataset, < code > XLSX.utils.json_to_sheet< / code > generates a worksheet:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < code > XLSX.utils.book_new< / code > creates a new workbook and < code > XLSX.utils.book_append_sheet< / code >
appends a worksheet to the workbook. The new worksheet will be called "Dates":< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Dates"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < strong > Process Data< / strong > < / p >
< p > < em > Fixing headers< / em > < / p >
< p > By default, < code > json_to_sheet< / code > creates a worksheet with a header row. In this case,
the headers come from the JS object keys: "name" and "birthday".< / p >
< p > The headers are in cells A1 and B1. < code > XLSX.utils.sheet_add_aoa< / code > can write text
values to the existing worksheet starting at cell A1:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Name"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Birthday"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s" > "A1"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Fixing Column Widths< / em > < / p >
< p > Some of the names are longer than the default column width. Column widths are
set by < a href = "#row-and-column-properties" > setting the < code > "!cols"< / code > worksheet property< / a > .< / p >
< p > The following line sets the width of column A to approximately 10 characters:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!cols"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > wch< / span > : < span class = "pl-c1" > 10< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // set column A width to 10 characters< / span > < / pre > < / div >
< p > One < code > Array#reduce< / code > call over < code > rows< / code > can calculate the maximum width:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-s1" > max_width< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > reduce< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > w< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-v" > Math< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > max< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > w< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > length< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 10< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!cols"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > wch< / span > : < span class = "pl-s1" > max_width< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Note: If the starting point was a file or HTML table, < code > XLSX.utils.sheet_to_json< / code >
will generate an array of JS objects.< / p >
< p > < strong > Package and Release Data< / strong > < / p >
< p > < code > XLSX.writeFile< / code > creates a spreadsheet file and tries to write it to the system.
In the browser, it will try to prompt the user to download the file. In NodeJS,
it will write to the local directory.< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Presidents.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < strong > Complete Example< / strong > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // Uncomment the next line for use in NodeJS:< / span >
< span class = "pl-c" > // const XLSX = require("xlsx"), axios = require("axios");< / span >
< span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* fetch JSON data and parse */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > url< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "https://theunitedstates.io/congress-legislators/executive.json"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > raw_data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > axios< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > responseType< / span > : < span class = "pl-s" > "json"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > data< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* filter for the Presidents */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > prez< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > raw_data< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > filter< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > row< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > terms< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > some< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > term< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > term< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > type< / span > < span class = "pl-c1" > ===< / span > < span class = "pl-s" > "prez"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* flatten objects */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > prez< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > row< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c1" > name< / span > : < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > first< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s" > " "< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > last< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > birthday< / span > : < span class = "pl-s1" > row< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > bio< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > birthday< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* generate worksheet and workbook */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Dates"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* fix headers */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Name"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Birthday"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s" > "A1"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* calculate column width */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > max_width< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > reduce< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > w< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-v" > Math< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > max< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > w< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > length< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 10< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!cols"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > wch< / span > : < span class = "pl-s1" > max_width< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* create an XLSX file and try to save to Presidents.xlsx */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Presidents.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For use in the web browser, assuming the snippet is saved to < code > snippet.js< / code > ,
script tags should be used to include the < code > axios< / code > and < code > xlsx< / code > standalone builds:< / p >
2022-04-14 17:50:18 +00:00
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://unpkg.com/axios/dist/axios.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > snippet.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< / details >
< p > < em > File formats are implementation details< / em > < / p >
< p > The parser covers a wide gamut of common spreadsheet file formats to ensure that
"HTML-saved-as-XLS" files work as well as actual XLS or XLSX files.< / p >
< p > The writer supports a number of common output formats for broad compatibility
with the data ecosystem.< / p >
< p > To the greatest extent possible, data processing code should not have to worry
about the specific file formats involved.< / p >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-js-ecosystem-demos" class = "anchor" href = "#js-ecosystem-demos" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > JS Ecosystem Demos< / h3 >
2021-09-12 09:16:01 +00:00
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/" > < code > demos< / code > directory< / a > includes sample projects for:< / p >
2020-01-28 05:02:07 +00:00
< p > < strong > Frameworks and APIs< / strong > < / p >
< ul >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/angular/" > < code > angularjs< / code > < / a > < / li >
2022-02-01 06:12:44 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/angular2/" > < code > angular and ionic< / code > < / a > < / li >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/knockout/" > < code > knockout< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/meteor/" > < code > meteor< / code > < / a > < / li >
2022-04-14 17:50:18 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/react/" > < code > react, react-native, next< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/vue/" > < code > vue 2.x, weex, nuxt< / code > < / a > < / li >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/xhr/" > < code > XMLHttpRequest and fetch< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/server/" > < code > nodejs server< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/database/" > < code > databases and key/value stores< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/array/" > < code > typed arrays and math< / code > < / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< p > < strong > Bundlers and Tooling< / strong > < / p >
< ul >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/browserify/" > < code > browserify< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/fusebox/" > < code > fusebox< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/parcel/" > < code > parcel< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/requirejs/" > < code > requirejs< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/rollup/" > < code > rollup< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/systemjs/" > < code > systemjs< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/typescript/" > < code > typescript< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/webpack/" > < code > webpack 2.x< / code > < / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< p > < strong > Platforms and Integrations< / strong > < / p >
< ul >
2022-02-14 02:02:46 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/deno/" > < code > deno< / code > < / a > < / li >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/electron/" > < code > electron application< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/nwjs/" > < code > nw.js application< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/chrome/" > < code > Chrome / Chromium extensions< / code > < / a > < / li >
2022-02-14 02:02:46 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/google-sheet/" > < code > Download a Google Sheet locally< / code > < / a > < / li >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/extendscript/" > < code > Adobe ExtendScript< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/headless/" > < code > Headless Browsers< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/datagrid/" > < code > canvas-datagrid< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/xspreadsheet/" > < code > x-spreadsheet< / code > < / a > < / li >
2022-03-25 04:01:40 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/react/modify/" > < code > react-data-grid< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/vue/modify/" > < code > vue3-table-light< / code > < / a > < / li >
2021-09-12 09:16:01 +00:00
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/altjs/" > < code > Swift JSC and other engines< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/function/" > < code > "serverless" functions< / code > < / a > < / li >
< li > < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/oldie/" > < code > internet explorer< / code > < / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
2021-09-12 09:16:01 +00:00
< p > Other examples are included in the < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/showcase/" > showcase< / a > .< / p >
2022-03-03 09:23:56 +00:00
< p > < a href = "https://sheetjs.com/demos/modify.html" rel = "nofollow" > https://sheetjs.com/demos/modify.html< / a > shows a complete example of reading,
modifying, and writing files.< / p >
< p > < a href = "https://github.com/SheetJS/sheetjs/blob/HEAD/bin/xlsx.njs" > https://github.com/SheetJS/sheetjs/blob/HEAD/bin/xlsx.njs< / a > is the command-line
tool included with node installations, reading spreadsheet files and exporting
the contents in various formats.< / p >
2020-01-28 05:02:07 +00:00
< h2 >
2022-02-14 02:02:46 +00:00
< a id = "user-content-acquiring-and-extracting-data" class = "anchor" href = "#acquiring-and-extracting-data" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Acquiring and Extracting Data< / h2 >
< h3 >
< a id = "user-content-parsing-workbooks" class = "anchor" href = "#parsing-workbooks" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Parsing Workbooks< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Extract data from spreadsheet bytes< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > read< / code > method can extract data from spreadsheet bytes stored in a JS string,
"binary string", NodeJS buffer or typed array (< code > Uint8Array< / code > or < code > ArrayBuffer< / code > ).< / p >
< p > < em > Read spreadsheet bytes from a local file and extract data< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > filename< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > readFile< / code > method attempts to read a spreadsheet file at the supplied path.
Browsers generally do not allow reading files in this way (it is deemed a
security risk), and attempts to read files in this way will throw an error.< / p >
< p > The second < code > opts< / code > argument is optional. < a href = "#parsing-options" > "Parsing Options"< / a >
covers the supported properties and behaviors.< / p >
< p > < strong > Examples< / strong > < / p >
< p > Here are a few common scenarios (click on each subtitle to see the code):< / p >
2020-01-28 05:02:07 +00:00
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Local file in a NodeJS server< / b > (click to show)< / summary >
< p > < code > readFile< / code > uses < code > fs.readFileSync< / code > under the hood:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For Node ESM, the < code > readFile< / code > helper is not enabled. Instead, < code > fs.readFileSync< / code >
should be used to read the file data as a < code > Buffer< / code > for use with < code > XLSX.read< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > readFileSync< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "fs"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > read< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx/xlsx.mjs"< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > buf< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > readFileSync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* buf is a Buffer */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > buf< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Local file in a Deno application< / b > (click to show)< / summary >
< p > < code > readFile< / code > uses < code > Deno.readFileSync< / code > under the hood:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // < span class = "pl-k" > @deno< / span > -types="https://deno.land/x/sheetjs/types/index.d.ts"< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'https://deno.land/x/sheetjs/xlsx.mjs'< / span >
2020-01-28 05:02:07 +00:00
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Applications reading files must be invoked with the < code > --allow-read< / code > flag. The
< a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/deno/" > < code > deno< / code > demo< / a > has more examples< / p >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > User-submitted file in a web page ("Drag-and-Drop")< / b > (click to show)< / summary >
< p > For modern websites targeting Chrome 76+, < code > File#arrayBuffer< / code > is recommended:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // XLSX is a global from the standalone script< / span >
< span class = "pl-k" > async< / span > < span class = "pl-k" > function< / span > < span class = "pl-en" > handleDropAsync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > stopPropagation< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > preventDefault< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > f< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > dataTransfer< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > files< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* f is a File */< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > f< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* data is an ArrayBuffer */< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > drop_dom_element< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addEventListener< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "drop"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > handleDropAsync< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-02-01 06:12:44 +00:00
< p > For maximal compatibility, the < code > FileReader< / code > API should be used:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > function< / span > < span class = "pl-en" > handleDrop< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > stopPropagation< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > preventDefault< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > f< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > dataTransfer< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > files< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* f is a File */< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > reader< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > FileReader< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > reader< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > onload< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > target< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > result< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* reader.readAsArrayBuffer(file) -> data will be an ArrayBuffer */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > reader< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readAsArrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > f< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > drop_dom_element< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addEventListener< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "drop"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > handleDrop< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < a href = "https://oss.sheetjs.com/sheetjs/" rel = "nofollow" > https://oss.sheetjs.com/sheetjs/< / a > demonstrates the FileReader technique.< / p >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > User-submitted file with an HTML INPUT element< / b > (click to show)< / summary >
< p > Starting with an HTML INPUT element with < code > type="file"< / code > :< / p >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > input< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > file< / span > " < span class = "pl-c1" > id< / span > ="< span class = "pl-s" > input_dom_element< / span > "< span class = "pl-kos" > > < / span > < / pre > < / div >
< p > For modern websites targeting Chrome 76+, < code > Blob#arrayBuffer< / code > is recommended:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // XLSX is a global from the standalone script< / span >
< span class = "pl-k" > async< / span > < span class = "pl-k" > function< / span > < span class = "pl-en" > handleFileAsync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > file< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > target< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > files< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > file< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* data is an ArrayBuffer */< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > input_dom_element< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addEventListener< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "change"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > handleFileAsync< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For broader support (including IE10+), the < code > FileReader< / code > approach is recommended:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > function< / span > < span class = "pl-en" > handleFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > file< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > target< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > files< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > reader< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > FileReader< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > reader< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > onload< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > target< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > result< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* reader.readAsArrayBuffer(file) -> data will be an ArrayBuffer */< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > target< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > result< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > reader< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readAsArrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > file< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-kos" > }< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > input_dom_element< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addEventListener< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "change"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > handleFile< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2021-09-12 09:16:01 +00:00
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/oldie/" > < code > oldie< / code > demo< / a > shows an IE-compatible fallback scenario.< / p >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Fetching a file in the web browser ("Ajax")< / b > (click to show)< / summary >
< p > For modern websites targeting Chrome 42+, < code > fetch< / code > is recommended:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // XLSX is a global from the standalone script< / span >
< span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > url< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "http://oss.sheetjs.com/test_files/formula_stress_test.xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* data is an ArrayBuffer */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For broader support, the < code > XMLHttpRequest< / code > approach is recommended:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > url< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "http://oss.sheetjs.com/test_files/formula_stress_test.xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* set up async GET request */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > req< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > XMLHttpRequest< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > open< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "GET"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > responseType< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "arraybuffer"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > onload< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > response< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > send< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/xhr/" > < code > xhr< / code > demo< / a > includes a longer discussion and more examples.< / p >
< p > < a href = "http://oss.sheetjs.com/sheetjs/ajax.html" rel = "nofollow" > http://oss.sheetjs.com/sheetjs/ajax.html< / a > shows fallback approaches for IE6+.< / p >
< / details >
< details >
< summary > < b > Local file in a PhotoShop or InDesign plugin< / b > (click to show)< / summary >
< p > < code > readFile< / code > wraps the < code > File< / code > logic in Photoshop and other ExtendScript targets.
The specified path should be an absolute path:< / p >
< div class = "highlight highlight-source-js" > < pre > #< span class = "pl-s1" > include< / span > < span class = "pl-s" > "xlsx.extendscript.js"< / span >
< span class = "pl-c" > /* Read test.xlsx from the Documents folder */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-v" > Folder< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > myDocuments< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s" > "/test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/extendscript/" > < code > extendscript< / code > demo< / a > includes a more complex example.< / p >
< / details >
< details >
< summary > < b > Local file in an Electron app< / b > (click to show)< / summary >
< p > < code > readFile< / code > can be used in the renderer process:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* From the renderer process */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > path< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Electron APIs have changed over time. The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/electron/" > < code > electron< / code > demo< / a >
shows a complete example and details the required version-specific settings.< / p >
2020-01-28 05:02:07 +00:00
< / details >
2022-02-14 02:02:46 +00:00
< details >
< summary > < b > Local file in a mobile app with React Native< / b > (click to show)< / summary >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/react" > < code > react< / code > demo< / a > includes a sample React Native app.< / p >
< p > Since React Native does not provide a way to read files from the filesystem, a
third-party library must be used. The following libraries have been tested:< / p >
2020-01-28 05:02:07 +00:00
< ul >
2022-02-14 02:02:46 +00:00
< li > < a href = "https://npm.im/react-native-file-access" rel = "nofollow" > < code > react-native-file-access< / code > < / a > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
2022-02-14 02:02:46 +00:00
< p > The < code > base64< / code > encoding returns strings compatible with the < code > base64< / code > type:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-v" > FileSystem< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "react-native-file-access"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > b64< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-v" > FileSystem< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > path< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "base64"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* b64 is a base64 string */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > b64< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > "base64"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< ul >
< li > < a href = "https://npm.im/react-native-fs" rel = "nofollow" > < code > react-native-fs< / code > < / a > < / li >
< / ul >
< p > The < code > ascii< / code > encoding returns binary strings compatible with the < code > binary< / code > type:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > readFile< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "react-native-fs"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > bstr< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > path< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "ascii"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* bstr is a binary string */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > bstr< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > "binary"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
2020-01-28 05:02:07 +00:00
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > NodeJS Server File Uploads< / b > (click to show)< / summary >
< p > < code > read< / code > can accept a NodeJS buffer. < code > readFile< / code > can read files generated by a
HTTP POST request body parser like < a href = "https://npm.im/formidable" rel = "nofollow" > < code > formidable< / code > < / a > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > http< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "http"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > formidable< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "formidable"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > server< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > http< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > createServer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > req< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > form< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-s1" > formidable< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > IncomingForm< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > form< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > parse< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > req< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > err< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > fields< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > files< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* grab the first file */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > f< / span > < span class = "pl-c1" > =< / span > < span class = "pl-v" > Object< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > entries< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > files< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > path< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > f< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > filepath< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > path< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > listen< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > process< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > env< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > PORT< / span > < span class = "pl-c1" > ||< / span > < span class = "pl-c1" > 7262< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/server" > < code > server< / code > demo< / a > has more advanced examples.< / p >
< / details >
< details >
< summary > < b > Download files in a NodeJS process< / b > (click to show)< / summary >
< p > Node 17.5 and 18.0 have native support for fetch:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* data is an ArrayBuffer */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For broader compatibility, third-party modules are recommended.< / p >
< p > < a href = "https://npm.im/request" rel = "nofollow" > < code > request< / code > < / a > requires a < code > null< / code > encoding to yield Buffers:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > request< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "request"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > request< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > url< / span > : < span class = "pl-s1" > url< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > encoding< / span > : < span class = "pl-c1" > null< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > err< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > resp< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > body< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > body< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < a href = "https://npm.im/axios" rel = "nofollow" > < code > axios< / code > < / a > works the same way in browser and in NodeJS:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > axios< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "axios"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > res< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > axios< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > get< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > responseType< / span > : < span class = "pl-s" > "arraybuffer"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* res.data is a Buffer */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > Download files in an Electron app< / b > (click to show)< / summary >
< p > The < code > net< / code > module in the main process can make HTTP/HTTPS requests to external
resources. Responses should be manually concatenated using < code > Buffer.concat< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > {< / span > net < span class = "pl-kos" > }< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "electron"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > req< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > net< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > request< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > on< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "response"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > bufs< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // this array will collect all of the buffers< / span >
< span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > on< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "data"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > chunk< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > bufs< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > chunk< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > on< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "end"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-v" > Buffer< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > concat< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > bufs< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > end< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Readable Streams in NodeJS< / b > (click to show)< / summary >
< p > When dealing with Readable Streams, the easiest approach is to buffer the stream
and process the whole thing at the end:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "fs"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > function< / span > < span class = "pl-en" > process_RS< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > cb< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > on< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "data"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > on< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "end"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > buffer< / span > < span class = "pl-c1" > =< / span > < span class = "pl-v" > Buffer< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > concat< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > buffer< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "buffer"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* DO SOMETHING WITH workbook IN THE CALLBACK */< / span >
< span class = "pl-s1" > cb< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
2022-02-14 02:02:46 +00:00
< / details >
< details >
< summary > < b > ReadableStream in the browser< / b > (click to show)< / summary >
< p > When dealing with < code > ReadableStream< / code > , the easiest approach is to buffer the stream
and process the whole thing at the end:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // XLSX is a global from the standalone script< / span >
2020-01-28 05:02:07 +00:00
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > async< / span > < span class = "pl-k" > function< / span > < span class = "pl-en" > process_RS< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* collect data */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > reader< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getReader< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > res< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > reader< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > value< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > value< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > res< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > done< / span > < span class = "pl-kos" > )< / span > < span class = "pl-k" > break< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* concat */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > out< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > Uint8Array< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > reduce< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > acc< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > v< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > acc< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s1" > v< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > length< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > let< / span > < span class = "pl-s1" > off< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ;< / span >
2022-05-11 21:03:03 +00:00
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > const< / span > < span class = "pl-s1" > u8< / span > < span class = "pl-k" > of< / span > < span class = "pl-s1" > buffers< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-s1" > out< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > set< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > u8< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > off< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > off< / span > < span class = "pl-c1" > +=< / span > < span class = "pl-s1" > u8< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > length< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-k" > return< / span > < span class = "pl-s1" > out< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > process_RS< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* data is Uint8Array */< / span >
2022-05-11 21:03:03 +00:00
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > 'array'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-02-14 02:02:46 +00:00
< / details >
< p > More detailed examples are covered in the < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/" > included demos< / a > < / p >
< h3 >
< a id = "user-content-processing-json-and-js-data" class = "anchor" href = "#processing-json-and-js-data" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Processing JSON and JS Data< / h3 >
< p > JSON and JS data tend to represent single worksheets. This section will use a
2022-03-03 09:23:56 +00:00
few utility functions to generate workbooks.< / p >
< p > < em > Create a new Workbook< / em > < / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > book_new< / code > utility function creates an empty workbook with no worksheets.< / p >
2022-03-03 09:23:56 +00:00
< p > Spreadsheet software generally require at least one worksheet and enforce the
requirement in the user interface. This library enforces the requirement at
write time, throwing errors if an empty workbook is passed to write functions.< / p >
2022-02-14 02:02:46 +00:00
< p > < strong > API< / strong > < / p >
< p > < em > Create a worksheet from an array of arrays of JS values< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > aoa_to_sheet< / code > utility function walks an "array of arrays" in row-major
order, generating a worksheet object. The following snippet generates a sheet
2022-03-03 09:23:56 +00:00
with cell < code > A1< / code > set to the string < code > A1< / code > , cell < code > B1< / code > set to < code > B1< / code > , etc:< / p >
2022-02-14 02:02:46 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "A1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "A2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C2"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "A3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C3"< / span > < span class = "pl-kos" > ]< / span >
2022-03-03 09:23:56 +00:00
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-02-14 02:02:46 +00:00
< p > < a href = "#array-of-arrays-input" > "Array of Arrays Input"< / a > describes the function and the
optional < code > opts< / code > argument in more detail.< / p >
< p > < em > Create a worksheet from an array of JS objects< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > jsa< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > json_to_sheet< / code > utility function walks an array of JS objects in order,
generating a worksheet object. By default, it will generate a header row and
one row per object in the array. The optional < code > opts< / code > argument has settings to
control the column order and header output.< / p >
2022-04-14 17:50:18 +00:00
< p > < a href = "#array-of-objects-input" > "Array of Objects Input"< / a > describes the function and
2022-02-14 02:02:46 +00:00
the optional < code > opts< / code > argument in more detail.< / p >
< p > < strong > Examples< / strong > < / p >
< p > < a href = "#the-zen-of-sheetjs" > "Zen of SheetJS"< / a > contains a detailed example "Get Data
from a JSON Endpoint and Generate a Workbook"< / p >
< p > < a href = "https://github.com/myliang/x-spreadsheet" > < code > x-spreadsheet< / code > < / a > is an interactive
data grid for previewing and modifying structured data in the web browser. The
< a href = "/demos/xspreadsheet" > < code > xspreadsheet< / code > demo< / a > includes a sample script with the
< code > xtos< / code > function for converting from x-spreadsheet data object to a workbook.
< a href = "https://oss.sheetjs.com/sheetjs/x-spreadsheet" rel = "nofollow" > https://oss.sheetjs.com/sheetjs/x-spreadsheet< / a > is a live demo.< / p >
< details >
< summary > < b > Records from a database query (SQL or no-SQL)< / b > (click to show)< / summary >
< p > The < a href = "/demos/database/" > < code > database< / code > demo< / a > includes examples of working with
databases and query results.< / p >
< / details >
< details >
< summary > < b > Numerical Computations with TensorFlow.js< / b > (click to show)< / summary >
< p > < a href = "@tensorflow/tfjs" > < code > @tensorflow/tfjs< / code > < / a > and other libraries expect data in simple
arrays, well-suited for worksheets where each column is a data vector. That is
the transpose of how most people use spreadsheets, where each row is a vector.< / p >
< p > When recovering data from < code > tfjs< / code > , the returned data points are stored in a typed
array. An array of arrays can be constructed with loops. < code > Array#unshift< / code > can
prepend a title row before the conversion:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > '@tensorflow/tfjs'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* suppose xs and ys are vectors (1D tensors) -> tfarr will be a typed array */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tfdata< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > stack< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > xs< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ys< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > transpose< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > shape< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tfdata< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > shape< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tfarr< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tfdata< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > dataSync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* construct the array of arrays */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > let< / span > < span class = "pl-s1" > j< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > j< / span > < span class = "pl-c1" > < < / span > < span class = "pl-s1" > shape< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > ++< / span > < span class = "pl-s1" > j< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > j< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > let< / span > < span class = "pl-s1" > i< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > i< / span > < span class = "pl-c1" > < < / span > < span class = "pl-s1" > shape< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > ++< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > j< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tfarr< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > j< / span > < span class = "pl-c1" > *< / span > < span class = "pl-s1" > shape< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* add headers to the top */< / span >
< span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > unshift< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "x"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "y"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* generate worksheet */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/array/" > < code > array< / code > demo< / a > shows a complete example.< / p >
< / details >
< h3 >
< a id = "user-content-processing-html-tables" class = "anchor" href = "#processing-html-tables" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Processing HTML Tables< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Create a worksheet by scraping an HTML TABLE in the page< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > dom_element< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > table_to_sheet< / code > utility function takes a DOM TABLE element and iterates
through the rows to generate a worksheet. The < code > opts< / code > argument is optional.
< a href = "#html-table-input" > "HTML Table Input"< / a > describes the function in more detail.< / p >
< p > < em > Create a workbook by scraping an HTML TABLE in the page< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_book< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > dom_element< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > table_to_book< / code > utility function follows the same logic as < code > table_to_sheet< / code > .
After generating a worksheet, it creates a blank workbook and appends the
spreadsheet.< / p >
< p > The options argument supports the same options as < code > table_to_sheet< / code > , with the
addition of a < code > sheet< / code > property to control the worksheet name. If the property
is missing or no options are specified, the default name < code > Sheet1< / code > is used.< / p >
< p > < strong > Examples< / strong > < / p >
< p > Here are a few common scenarios (click on each subtitle to see the code):< / p >
< details >
< summary > < b > HTML TABLE element in a webpage< / b > (click to show)< / summary >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-c" > < !-- include the standalone script and shim. this uses the UNPKG CDN --> < / span >
2022-04-14 17:50:18 +00:00
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-latest/package/dist/shim.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > < !-- example table with id attribute --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > table< / span > < span class = "pl-c1" > id< / span > ="< span class = "pl-s" > tableau< / span > "< span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > Sheet< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > JS< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 12345< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 67< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > table< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-c" > < !-- this block should appear after the table HTML and the standalone script --> < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > text/javascript< / span > "< span class = "pl-kos" > > < / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_book< / span > < span class = "pl-kos" > (< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "tableau"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< p > Multiple tables on a web page can be converted to individual worksheets:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* create new workbook */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* convert table "table1" to worksheet named "Sheet1" */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > sheet1< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "table1"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheet1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* convert table "table2" to worksheet named "Sheet2" */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > sheet2< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "table2"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheet2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet2"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* workbook now has 2 worksheets */< / span > < / pre > < / div >
< p > Alternatively, the HTML code can be extracted and parsed:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > htmlstr< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "tableau"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > outerHTML< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > htmlstr< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "string"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > Chrome/Chromium Extension< / b > (click to show)< / summary >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/chrome/" > < code > chrome< / code > demo< / a > shows a complete example and details the
required permissions and other settings.< / p >
< p > In an extension, it is recommended to generate the workbook in a content script
and pass the object back to the extension:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* in the worker script */< / span >
< span class = "pl-s1" > chrome< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > runtime< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > onMessage< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addListener< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > msg< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sender< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > cb< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* pass a message like { sheetjs: true } from the extension to scrape */< / span >
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > msg< / span > < span class = "pl-c1" > ||< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > msg< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > sheetjs< / span > < span class = "pl-kos" > )< / span > < span class = "pl-k" > return< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* create a new workbook */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* loop through each table element */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > tables< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementsByTagName< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "table"< / span > < span class = "pl-kos" > )< / span >
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > var< / span > < span class = "pl-s1" > i< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > i< / span > < span class = "pl-c1" > < < / span > < span class = "pl-s1" > tables< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > length< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > ++< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > tables< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Table"< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* pass back to the extension */< / span >
< span class = "pl-k" > return< / span > < span class = "pl-s1" > cb< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > Server-Side HTML Tables with Headless Chrome< / b > (click to show)< / summary >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/headless/" > < code > headless< / code > demo< / a > includes a complete demo to convert HTML
files to XLSB workbooks. The core idea is to add the script to the page, parse
the table in the page context, generate a < code > base64< / code > workbook and send it back
for further processing:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > {< / span > readFileSync < span class = "pl-kos" > }< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "fs"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > puppeteer< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "puppeteer"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > url< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > `https://sheetjs.com/demos/table`< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* get the standalone build source (node_modules/xlsx/dist/xlsx.full.min.js) */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > lib< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > readFileSync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > resolve< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx/dist/xlsx.full.min.js"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "utf8"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* start browser and go to web page */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > browser< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > puppeteer< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > launch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > page< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > await< / span > < span class = "pl-s1" > browser< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > newPage< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > await< / span > < span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > goto< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > waitUntil< / span > : < span class = "pl-s" > "networkidle2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* inject library */< / span >
< span class = "pl-k" > await< / span > < span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addScriptTag< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > content< / span > : < span class = "pl-s1" > lib< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* this function `s5s` will be called by the script below, receiving the Base64-encoded file */< / span >
< span class = "pl-k" > await< / span > < span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > exposeFunction< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "s5s"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > b64< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > b64< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > "base64"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* generate XLSB file in webpage context and send back result */< / span >
< span class = "pl-k" > await< / span > < span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > addScriptTag< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > content< / span > : < span class = "pl-s" > `< / span >
< span class = "pl-s" > /* call table_to_book on first table */< / span >
< span class = "pl-s" > var workbook = XLSX.utils.table_to_book(document.querySelector("TABLE"));< / span >
< span class = "pl-s" > < / span >
< span class = "pl-s" > /* generate XLSX file */< / span >
< span class = "pl-s" > var b64 = XLSX.write(workbook, {type: "base64", bookType: "xlsb"});< / span >
< span class = "pl-s" > < / span >
< span class = "pl-s" > /* call "s5s" hook exposed from the node process */< / span >
< span class = "pl-s" > window.s5s(b64);< / span >
< span class = "pl-s" > `< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* cleanup */< / span >
< span class = "pl-k" > await< / span > < span class = "pl-s1" > browser< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > close< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > Server-Side HTML Tables with Headless WebKit< / b > (click to show)< / summary >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/headless/" > < code > headless< / code > demo< / a > includes a complete demo to convert HTML
files to XLSB workbooks using < a href = "https://phantomjs.org/" rel = "nofollow" > PhantomJS< / a > . The core idea
is to add the script to the page, parse the table in the page context, generate
a < code > binary< / code > workbook and send it back for further processing:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'xlsx'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > page< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'webpage'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > create< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* this code will be run in the page */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > code< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "function(){"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c" > /* call table_to_book on first table */< / span >
< span class = "pl-s" > "var wb = XLSX.utils.table_to_book(document.body.getElementsByTagName('table')[0]);"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c" > /* generate XLSB file and return binary string */< / span >
< span class = "pl-s" > "return XLSX.write(wb, {type: 'binary', bookType: 'xlsb'});"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-s" > "}"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > join< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > ""< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > open< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'https://sheetjs.com/demos/table'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* Load the browser script from the UNPKG CDN */< / span >
2022-04-14 17:50:18 +00:00
< span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > includeJs< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* The code will return an XLSB file encoded as binary string */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > bin< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > page< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > evaluateJavaScript< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > code< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > bin< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > "binary"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* DO SOMETHING WITH workbook HERE */< / span >
< span class = "pl-s1" > phantom< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > exit< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > NodeJS HTML Tables without a browser< / b > (click to show)< / summary >
< p > NodeJS does not include a DOM implementation and Puppeteer requires a hefty
Chromium build. < a href = "https://npm.im/jsdom" rel = "nofollow" > < code > jsdom< / code > < / a > is a lightweight alternative:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > {< / span > readFileSync < span class = "pl-kos" > }< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "fs"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > JSDOM< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "jsdom"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* obtain HTML string. This example reads from test.html */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > html_str< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > readFileSync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "test.html"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "utf8"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* get first TABLE element */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > doc< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-c1" > JSDOM< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > html_str< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > window< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > querySelector< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "table"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* generate workbook */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_book< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > doc< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h2 >
2022-03-03 09:23:56 +00:00
< a id = "user-content-processing-data" class = "anchor" href = "#processing-data" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Processing Data< / h2 >
< p > The < a href = "#common-spreadsheet-format" > "Common Spreadsheet Format"< / a > is a simple object
representation of the core concepts of a workbook. The utility functions work
with the object representation and are intended to handle common use cases.< / p >
< h3 >
< a id = "user-content-modifying-workbook-structure" class = "anchor" href = "#modifying-workbook-structure" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Modifying Workbook Structure< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Append a Worksheet to a Workbook< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheet_name< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > book_append_sheet< / code > utility function appends a worksheet to the workbook.
The third argument specifies the desired worksheet name. Multiple worksheets can
2022-03-25 04:01:40 +00:00
be added to a workbook by calling the function multiple times. If the worksheet
name is already used in the workbook, it will throw an error.< / p >
< p > < em > Append a Worksheet to a Workbook and find a unique name< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > new_name< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > name< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > If the fourth argument is < code > true< / code > , the function will start with the specified
worksheet name. If the sheet name exists in the workbook, a new worksheet name
will be chosen by finding the name stem and incrementing the counter:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheetA< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // Sheet2< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheetB< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // Sheet3< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheetC< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // Sheet4< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > sheetD< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet2"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // Sheet5< / span > < / pre > < / div >
2022-03-03 09:23:56 +00:00
< p > < em > List the Worksheet names in tab order< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > wsnames< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > SheetNames< / code > property of the workbook object is a list of the worksheet
names in "tab order". API functions will look at this array.< / p >
< p > < em > Replace a Worksheet in place< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > sheet_name< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > new_worksheet< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > Sheets< / code > property of the workbook object is an object whose keys are names
and whose values are worksheet objects. By reassigning to a property of the
< code > Sheets< / code > object, the worksheet object can be changed without disrupting the
rest of the worksheet structure.< / p >
< p > < strong > Examples< / strong > < / p >
2020-01-28 05:02:07 +00:00
< details >
2022-03-03 09:23:56 +00:00
< summary > < b > Add a new worksheet to a workbook< / b > (click to show)< / summary >
< p > This example uses < a href = "#array-of-arrays-input" > < code > XLSX.utils.aoa_to_sheet< / code > < / a > .< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws_name< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2022-03-03 09:23:56 +00:00
< span class = "pl-c" > /* Create worksheet */< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws_data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "S"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "h"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "t"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "J"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "S"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ]< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws_data< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Add the worksheet to the workbook */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ws_name< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
2022-03-03 09:23:56 +00:00
< h3 >
< a id = "user-content-modifying-cell-values" class = "anchor" href = "#modifying-cell-values" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Modifying Cell Values< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Modify a single cell value in a worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > new_value< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s1" > address< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Modify multiple cell values in a worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > sheet_add_aoa< / code > utility function modifies cell values in a worksheet. The
first argument is the worksheet object. The second argument is an array of
arrays of values. The < code > origin< / code > key of the third argument controls where cells
will be written. The following snippet sets < code > B3=1< / code > and < code > E5="abc"< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- Write 1 to cell B3< / span >
< span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- Do nothing in row 4< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c" > /*B5*/< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > /*C5*/< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > /*D5*/< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "abc"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c" > // < -- Write "abc" to cell E5< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s" > "B3"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < a href = "#array-of-arrays-input" > "Array of Arrays Input"< / a > describes the function and the
optional < code > opts< / code > argument in more detail.< / p >
< p > < strong > Examples< / strong > < / p >
2020-01-28 05:02:07 +00:00
< details >
2022-03-03 09:23:56 +00:00
< summary > < b > Appending rows to a worksheet< / b > (click to show)< / summary >
< p > The special origin value < code > -1< / code > instructs < code > sheet_add_aoa< / code > to start in column A of
the row after the last row in the range, appending the data:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "first row after data"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "second row after data"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ]< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
2022-03-03 09:23:56 +00:00
< a id = "user-content-modifying-other-worksheet--workbook--cell-properties" class = "anchor" href = "#modifying-other-worksheet--workbook--cell-properties" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Modifying Other Worksheet / Workbook / Cell Properties< / h3 >
< p > The < a href = "#common-spreadsheet-format" > "Common Spreadsheet Format"< / a > section describes
the object structures in greater detail.< / p >
2020-01-28 05:02:07 +00:00
< h2 >
2022-02-14 02:02:46 +00:00
< a id = "user-content-packaging-and-releasing-data" class = "anchor" href = "#packaging-and-releasing-data" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Packaging and Releasing Data< / h2 >
< h3 >
< a id = "user-content-writing-workbooks" class = "anchor" href = "#writing-workbooks" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Writing Workbooks< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Generate spreadsheet bytes (file) from data< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > write< / code > method attempts to package data from the workbook into a file in
memory. By default, XLSX files are generated, but that can be controlled with
the < code > bookType< / code > property of the < code > opts< / code > argument. Based on the < code > type< / code > option,
the data can be stored as a "binary string", JS string, < code > Uint8Array< / code > or Buffer.< / p >
< p > The second < code > opts< / code > argument is required. < a href = "#writing-options" > "Writing Options"< / a >
covers the supported properties and behaviors.< / p >
< p > < em > Generate and attempt to save file< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > filename< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > writeFile< / code > method packages the data and attempts to save the new file. The
export file format is determined by the extension of < code > filename< / code > (< code > SheetJS.xlsx< / code >
signals XLSX export, < code > SheetJS.xlsb< / code > signals XLSB export, etc).< / p >
< p > The < code > writeFile< / code > method uses platform-specific APIs to initiate the file save. In
NodeJS, < code > fs.readFileSync< / code > can create a file. In the web browser, a download is
attempted using the HTML5 < code > download< / code > attribute, with fallbacks for IE.< / p >
< p > < em > Generate and attempt to save an XLSX file< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFileXLSX< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > filename< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > writeFile< / code > method embeds a number of different export functions. This is
2022-03-03 09:23:56 +00:00
great for developer experience but not amenable to tree shaking using the
current developer tools. When only XLSX exports are needed, this method avoids
referencing the other export functions.< / p >
2022-02-14 02:02:46 +00:00
< p > The second < code > opts< / code > argument is optional. < a href = "#writing-options" > "Writing Options"< / a >
covers the supported properties and behaviors.< / p >
< p > < strong > Examples< / strong > < / p >
< details >
< summary > < b > Local file in a NodeJS server< / b > (click to show)< / summary >
< p > < code > writeFile< / code > uses < code > fs.writeFileSync< / code > in server environments:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* output format determined by filename */< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "out.xlsb"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For Node ESM, the < code > writeFile< / code > helper is not enabled. Instead, < code > fs.writeFileSync< / code >
should be used to write the file data to a < code > Buffer< / code > for use with < code > XLSX.write< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > writeFileSync< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "fs"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > write< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx/xlsx.mjs"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > buf< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > : < span class = "pl-s" > "buffer"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bookType< / span > : < span class = "pl-s" > "xlsb"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* buf is a Buffer */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > writeFileSync< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "out.xlsb"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > buf< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > Local file in a Deno application< / b > (click to show)< / summary >
< p > < code > writeFile< / code > uses < code > Deno.writeFileSync< / code > under the hood:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // < span class = "pl-k" > @deno< / span > -types="https://deno.land/x/sheetjs/types/index.d.ts"< / span >
< span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'https://deno.land/x/sheetjs/xlsx.mjs'< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Applications writing files must be invoked with the < code > --allow-write< / code > flag. The
< a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/deno/" > < code > deno< / code > demo< / a > has more examples< / p >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Local file in a PhotoShop or InDesign plugin< / b > (click to show)< / summary >
2020-01-28 05:02:07 +00:00
< p > < code > writeFile< / code > wraps the < code > File< / code > logic in Photoshop and other ExtendScript targets.
The specified path should be an absolute path:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > #< span class = "pl-s1" > include< / span > < span class = "pl-s" > "xlsx.extendscript.js"< / span >
2022-02-14 02:02:46 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* output format determined by filename */< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "out.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* at this point, out.xlsx is a file that you can distribute */< / span > < / pre > < / div >
2021-09-12 09:16:01 +00:00
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/extendscript/" > < code > extendscript< / code > demo< / a > includes a more complex example.< / p >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Download a file in the browser to the user machine< / b > (click to show)< / summary >
2020-01-28 05:02:07 +00:00
< p > < code > XLSX.writeFile< / code > wraps a few techniques for triggering a file save:< / p >
< ul >
< li >
< code > URL< / code > browser API creates an object URL for the file, which the library uses
by creating a link and forcing a click. It is supported in modern browsers.< / li >
< li >
< code > msSaveBlob< / code > is an IE10+ API for triggering a file save.< / li >
< li >
< code > IE_FileSave< / code > uses VBScript and ActiveX to write a file in IE6+ for Windows
XP and Windows 7. The shim must be included in the containing HTML page.< / li >
< / ul >
< p > There is no standard way to determine if the actual file has been downloaded.< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* output format determined by filename */< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "out.xlsb"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* at this point, out.xlsb will have been downloaded */< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > Download a file in legacy browsers< / b > (click to show)< / summary >
2020-01-28 05:02:07 +00:00
< p > < code > XLSX.writeFile< / code > techniques work for most modern browsers as well as older IE.
For much older browsers, there are workarounds implemented by wrapper libraries.< / p >
< p > < a href = "https://github.com/eligrey/FileSaver.js/" > < code > FileSaver.js< / code > < / a > implements < code > saveAs< / code > .
Note: < code > XLSX.writeFile< / code > will automatically call < code > saveAs< / code > if available.< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* bookType can be any supported output type */< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wopts< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > bookType< / span > :< span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bookSST< / span > :< span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "array"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wbout< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > wopts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* the saveAs call downloads a file on the local machine */< / span >
< span class = "pl-en" > saveAs< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > Blob< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > wbout< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "application/octet-stream"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > < a href = "https://github.com/dcneiner/downloadify" > < code > Downloadify< / code > < / a > uses a Flash SWF button
to generate local files, suitable for environments where ActiveX is unavailable:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-v" > Downloadify< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > create< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > id< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-c" > /* other options are required! read the downloadify docs for more info */< / span >
< span class = "pl-c1" > filename< / span > : < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-en" > data< / span > : < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-k" > return< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > bookType< / span > :< span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "base64"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > append< / span > : < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > dataType< / span > : < span class = "pl-s" > "base64"< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2021-09-12 09:16:01 +00:00
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/oldie/" > < code > oldie< / code > demo< / a > shows an IE-compatible fallback scenario.< / p >
2020-01-28 05:02:07 +00:00
< / details >
2022-02-14 02:02:46 +00:00
< details >
< summary > < b > Browser upload file (ajax)< / b > (click to show)< / summary >
< p > A complete example using XHR is < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/xhr/" > included in the XHR demo< / a > , along
with examples for fetch and wrapper libraries. This example assumes the server
can handle Base64-encoded files (see the demo for a basic nodejs server):< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* in this example, send a base64 string to the server */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wopts< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > bookType< / span > :< span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bookSST< / span > :< span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "base64"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wbout< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > wopts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > req< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > XMLHttpRequest< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > open< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "POST"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "/upload"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > formdata< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > FormData< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > formdata< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > append< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "file"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // < -- server expects `file` to hold name< / span >
< span class = "pl-s1" > formdata< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > append< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "data"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > wbout< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // < -- `data` holds the base64-encoded data< / span >
< span class = "pl-s1" > req< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > send< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > formdata< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
< details >
< summary > < b > PhantomJS (Headless Webkit) File Generation< / b > (click to show)< / summary >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/headless/" > < code > headless< / code > demo< / a > includes a complete demo to convert HTML
files to XLSB workbooks using < a href = "https://phantomjs.org/" rel = "nofollow" > PhantomJS< / a > . PhantomJS
< code > fs.write< / code > supports writing files from the main process but has a different
interface from the NodeJS < code > fs< / code > module:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'xlsx'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'fs'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* generate a binary string */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > bin< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > type< / span > :< span class = "pl-s" > "binary"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bookType< / span > : < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* write to file */< / span >
< span class = "pl-s1" > fs< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "test.xlsx"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > bin< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "wb"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Note: The section < a href = "#processing-html-tables" > "Processing HTML Tables"< / a > shows how
to generate a workbook from HTML tables in a page in "Headless WebKit".< / p >
< / details >
2021-09-12 09:16:01 +00:00
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/" > included demos< / a > cover mobile apps and other special deployments.< / p >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-writing-examples" class = "anchor" href = "#writing-examples" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Writing Examples< / h3 >
< ul >
< li >
< a href = "http://sheetjs.com/demos/table.html" rel = "nofollow" > http://sheetjs.com/demos/table.html< / a > exporting an HTML table< / li >
< li >
< a href = "http://sheetjs.com/demos/writexlsx.html" rel = "nofollow" > http://sheetjs.com/demos/writexlsx.html< / a > generates a simple file< / li >
< / ul >
< h3 >
< a id = "user-content-streaming-write" class = "anchor" href = "#streaming-write" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Streaming Write< / h3 >
< p > The streaming write functions are available in the < code > XLSX.stream< / code > object. They
2022-03-25 04:01:40 +00:00
take the same arguments as the normal write functions but return a NodeJS
Readable Stream.< / p >
2020-01-28 05:02:07 +00:00
< ul >
< li >
< code > XLSX.stream.to_csv< / code > is the streaming version of < code > XLSX.utils.sheet_to_csv< / code > .< / li >
< li >
< code > XLSX.stream.to_html< / code > is the streaming version of < code > XLSX.utils.sheet_to_html< / code > .< / li >
< li >
< code > XLSX.stream.to_json< / code > is the streaming version of < code > XLSX.utils.sheet_to_json< / code > .< / li >
< / ul >
< details >
< summary > < b > nodejs convert to CSV and write file< / b > (click to show)< / summary >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > output_file_name< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "out.csv"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > to_csv< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > pipe< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > fs< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > createWriteStream< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > output_file_name< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< details >
< summary > < b > nodejs write JSON stream to screen< / b > (click to show)< / summary >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* to_json returns an object-mode stream */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > stream< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > raw< / span > :< span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* the following stream converts JS objects to text via JSON.stringify */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > conv< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > new< / span > < span class = "pl-v" > Transform< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > writableObjectMode< / span > :< span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > conv< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > _transform< / span > < span class = "pl-c1" > =< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > obj< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > cb< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > cb< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > null< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > JSON< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > stringify< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > obj< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > +< / span > < span class = "pl-s" > "\n"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-s1" > stream< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > pipe< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > conv< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-s1" > conv< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > pipe< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > process< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > stdout< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
2022-03-25 04:01:40 +00:00
< details >
< summary > < b > Exporting NUMBERS files< / b > (click to show)< / summary >
< p > The NUMBERS writer requires a fairly large base. The supplementary < code > xlsx.zahl< / code >
scripts provide support. < code > xlsx.zahl.js< / code > is designed for standalone and NodeJS
use, while < code > xlsx.zahl.mjs< / code > is suitable for ESM.< / p >
< p > < em > Browser< / em > < / p >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > meta< / span > < span class = "pl-c1" > charset< / span > ="< span class = "pl-s" > utf8< / span > "< span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > xlsx.zahl.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "< 3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "விரிதாள்"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 72< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Arbeitsblätter"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 62< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "数据"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "textport.numbers"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > numbers< / span > : < span class = "pl-c1" > XLSX_ZAHL< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > compression< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< p > < em > Node< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "./xlsx.flow"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-c1" > XLSX_ZAHL< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "./dist/xlsx.zahl"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "< 3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "விரிதாள்"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 72< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Arbeitsblätter"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 62< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "数据"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "textport.numbers"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > numbers< / span > : < span class = "pl-c1" > XLSX_ZAHL< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > compression< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Deno< / em > < / p >
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-c1" > *< / span > < span class = "pl-k" > as< / span > < span class = "pl-smi" > XLSX< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > './xlsx.mjs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-smi" > XLSX_ZAHL< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > './dist/xlsx.zahl.mjs'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "< 3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "விரிதாள்"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 72< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Arbeitsblätter"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 62< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "数据"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-smi" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_append_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-smi" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > writeFile< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "textports.numbers"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > numbers< / span > : < span class = "pl-smi" > XLSX_ZAHL< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > compression< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
2020-01-28 05:02:07 +00:00
< p > < a href = "https://github.com/sheetjs/sheetaki" > https://github.com/sheetjs/sheetaki< / a > pipes write streams to nodejs response.< / p >
2022-02-14 02:02:46 +00:00
< h3 >
< a id = "user-content-generating-json-and-js-data" class = "anchor" href = "#generating-json-and-js-data" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Generating JSON and JS Data< / h3 >
< p > JSON and JS data tend to represent single worksheets. The utility functions in
this section work with single worksheets.< / p >
< p > The < a href = "#common-spreadsheet-format" > "Common Spreadsheet Format"< / a > section describes
the object structure in more detail. < code > workbook.SheetNames< / code > is an ordered list
of the worksheet names. < code > workbook.Sheets< / code > is an object whose keys are sheet
names and whose values are worksheet objects.< / p >
< p > The "first worksheet" is stored at < code > workbook.Sheets[workbook.SheetNames[0]]< / code > .< / p >
< p > < strong > API< / strong > < / p >
< p > < em > Create an array of JS objects from a worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > jsa< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Create an array of arrays of JS values from a worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > ...< span class = "pl-s1" > opts< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > sheet_to_json< / code > utility function walks a workbook in row-major order,
generating an array of objects. The second < code > opts< / code > argument controls a number of
export decisions including the type of values (JS values or formatted text). The
< a href = "#json" > "JSON"< / a > section describes the argument in more detail.< / p >
< p > By default, < code > sheet_to_json< / code > scans the first row and uses the values as headers.
With the < code > header: 1< / code > option, the function exports an array of arrays of values.< / p >
< p > < strong > Examples< / strong > < / p >
< p > < a href = "https://github.com/myliang/x-spreadsheet" > < code > x-spreadsheet< / code > < / a > is an interactive
data grid for previewing and modifying structured data in the web browser. The
< a href = "/demos/xspreadsheet" > < code > xspreadsheet< / code > demo< / a > includes a sample script with the
< code > stox< / code > function for converting from a workbook to x-spreadsheet data object.
< a href = "https://oss.sheetjs.com/sheetjs/x-spreadsheet" rel = "nofollow" > https://oss.sheetjs.com/sheetjs/x-spreadsheet< / a > is a live demo.< / p >
< details >
< summary > < b > Previewing data in a React data grid< / b > (click to show)< / summary >
< p > < a href = "https://npm.im/react-data-grid" rel = "nofollow" > < code > react-data-grid< / code > < / a > is a data grid tailored for
react. It expects two properties: < code > rows< / code > of data objects and < code > columns< / code > which
describe the columns. For the purposes of massaging the data to fit the react
data grid API it is easiest to start from an array of arrays.< / p >
< p > This demo starts by fetching a remote file and using < code > XLSX.read< / code > to extract:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > useEffect< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > useState< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "react"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-v" > DataGrid< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "react-data-grid"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > read< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > utils< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > url< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "https://oss.sheetjs.com/test_files/RkNumber.xls"< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > export< / span > < span class = "pl-k" > default< / span > < span class = "pl-k" > function< / span > < span class = "pl-v" > App< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > columns< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > setColumns< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > useState< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > setRows< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > useState< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-en" > useEffect< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > url< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > WTF< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* use sheet_to_json with header: 1 to generate an array of arrays */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* see react-data-grid docs to understand the shape of the expected data */< / span >
< span class = "pl-s1" > setColumns< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > key< / span > : < span class = "pl-s1" > r< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > name< / span > : < span class = "pl-s1" > r< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > setRows< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > slice< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > reduce< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > acc< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-s1" > acc< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > data< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > i< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > return< / span > < span class = "pl-s1" > acc< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > return< / span > < span class = "pl-c1" > < < / span > < span class = "pl-ent" > DataGrid< / span > < span class = "pl-c1" > columns< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > columns< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c1" > rows< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > rows< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c1" > /< / span > < span class = "pl-c1" > > < / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
< / details >
2022-03-25 04:01:40 +00:00
< details >
< summary > < b > Previewing data in a VueJS data grid< / b > (click to show)< / summary >
< p > < a href = "https://github.com/linmasahiro/vue3-table-lite" > < code > vue3-table-lite< / code > < / a > is a simple
VueJS 3 data table. It is featured < a href = "/demos/vue/modify/" > in the VueJS demo< / a > .< / p >
< / details >
2022-02-14 02:02:46 +00:00
< details >
< summary > < b > Populating a database (SQL or no-SQL)< / b > (click to show)< / summary >
< p > The < a href = "/demos/database/" > < code > database< / code > demo< / a > includes examples of working with
databases and query results.< / p >
< / details >
< details >
< summary > < b > Numerical Computations with TensorFlow.js< / b > (click to show)< / summary >
< p > < a href = "@tensorflow/tfjs" > < code > @tensorflow/tfjs< / code > < / a > and other libraries expect data in simple
arrays, well-suited for worksheets where each column is a data vector. That is
the transpose of how most people use spreadsheets, where each row is a vector.< / p >
< p > A single < code > Array#map< / code > can pull individual named rows from < code > sheet_to_json< / code > export:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > '@tensorflow/tfjs'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > key< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "age"< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // this is the field we want to pull< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > ages< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > r< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > r< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > key< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf_data< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > tensor1d< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ages< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > All fields can be processed at once using a transpose of the 2D tensor generated
with the < code > sheet_to_json< / code > export with < code > header: 1< / code > . The first row, if it contains
header labels, should be removed with a slice:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > const< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > require< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > '@tensorflow/tfjs'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* array of arrays of the data starting on the second row */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > slice< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* dataset in the "correct orientation" */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf_dataset< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tf< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > tensor2d< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > aoa< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > transpose< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* pull out each dataset with a slice */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf_field0< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tf_dataset< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > slice< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > tensor< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > shape< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > flatten< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > tf_field1< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > tf_dataset< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > slice< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > tensor< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > shape< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > flatten< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/array/" > < code > array< / code > demo< / a > shows a complete example.< / p >
< / details >
< h3 >
< a id = "user-content-generating-html-tables" class = "anchor" href = "#generating-html-tables" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Generating HTML Tables< / h3 >
< p > < strong > API< / strong > < / p >
< p > < em > Generate HTML Table from Worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > html< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < code > sheet_to_html< / code > utility function generates HTML code based on the worksheet
data. Each cell in the worksheet is mapped to a < code > < TD> < / code > element. Merged cells
in the worksheet are serialized by setting < code > colspan< / code > and < code > rowspan< / code > attributes.< / p >
< p > < strong > Examples< / strong > < / p >
< p > The < code > sheet_to_html< / code > utility function generates HTML code that can be added to
any DOM element by setting the < code > innerHTML< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > container< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "tavolo"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > container< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > innerHTML< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Combining with < code > fetch< / code > , constructing a site from a workbook is straightforward:< / p >
< details >
< summary > < b > Vanilla JS + HTML fetch workbook and generate table previews< / b > (click to show)< / summary >
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > body< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > style< / span > < span class = "pl-kos" > > < / span > < span class = "pl-ent" > TABLE< / span > { < span class = "pl-c1" > border-collapse< / span > < span class = "pl-kos" > :< / span > collapse; } < span class = "pl-ent" > TD< / span > { < span class = "pl-c1" > border< / span > < span class = "pl-kos" > :< / span > < span class = "pl-c1" > 1< span class = "pl-smi" > px< / span > < / span > solid; }< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > style< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > div< / span > < span class = "pl-c1" > id< / span > ="< span class = "pl-s" > tavolo< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > div< / span > < span class = "pl-kos" > > < / span >
2022-04-14 17:50:18 +00:00
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > src< / span > ="< span class = "pl-s" > https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js< / span > "< span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
2022-02-14 02:02:46 +00:00
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > script< / span > < span class = "pl-c1" > type< / span > ="< span class = "pl-s" > text/javascript< / span > "< span class = "pl-kos" > > < / span >
< span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* fetch and parse workbook -- see the fetch example for details */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "sheetjs.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > let< / span > < span class = "pl-s1" > output< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* loop through the worksheet names in order */< / span >
< span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > forEach< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > name< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* generate HTML from the corresponding worksheets */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > name< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > html< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* add a header with the title name followed by the table */< / span >
< span class = "pl-s1" > output< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > `< H3> < span class = "pl-s1" > < span class = "pl-kos" > ${< / span > < span class = "pl-s1" > name< / span > < span class = "pl-kos" > }< / span > < / span > < /H3> < span class = "pl-s1" > < span class = "pl-kos" > ${< / span > < span class = "pl-s1" > html< / span > < span class = "pl-kos" > }< / span > < / span > `< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* write to the DOM at the end */< / span >
< span class = "pl-s1" > tavolo< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > innerHTML< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > output< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > join< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "\n"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > script< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > body< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
< / details >
< details >
< summary > < b > React fetch workbook and generate HTML table previews< / b > (click to show)< / summary >
< p > It is generally recommended to use a React-friendly workflow, but it is possible
to generate HTML and use it in React with < code > dangerouslySetInnerHTML< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > function< / span > < span class = "pl-v" > Tabeller< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > props< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* the workbook object is the state */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > setWorkbook< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-v" > React< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > useState< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > book_new< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* fetch and update the workbook with an effect */< / span >
< span class = "pl-v" > React< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > useEffect< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* fetch and parse workbook -- see the fetch example for details */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "sheetjs.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > setWorkbook< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > return< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > name< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > < < / span > < span class = "pl-c1" > > < / span >
< span class = "pl-c1" > < < / span > < span class = "pl-ent" > h3< / span > < span class = "pl-c1" > > < / span > name< span class = "pl-c1" > < < / span > < span class = "pl-c1" > /< / span > < span class = "pl-ent" > h3< / span > < span class = "pl-c1" > > < / span >
< span class = "pl-c1" > < < / span > < span class = "pl-ent" > div< / span > < span class = "pl-c1" > dangerouslySetInnerHTML< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* this __html mantra is needed to set the inner HTML */< / span >
< span class = "pl-c1" > __html< / span > : < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > name< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c1" > /< / span > < span class = "pl-c1" > > < / span >
< span class = "pl-c1" > < < / span > < span class = "pl-c1" > /< / span > < span class = "pl-c1" > > < / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/react" > < code > react< / code > demo< / a > includes more React examples.< / p >
< / details >
< details >
< summary > < b > VueJS fetch workbook and generate HTML table previews< / b > (click to show)< / summary >
< p > It is generally recommended to use a VueJS-friendly workflow, but it is possible
to generate HTML and use it in VueJS with the < code > v-html< / code > directive:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > read< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > utils< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'xlsx'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > import< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s1" > reactive< / span > < span class = "pl-kos" > }< / span > < span class = "pl-k" > from< / span > < span class = "pl-s" > 'vue'< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-v" > S5SComponent< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-en" > mounted< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > async< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* fetch and parse workbook -- see the fetch example for details */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-c1" > =< / span > < span class = "pl-en" > read< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > await< / span > < span class = "pl-en" > fetch< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > "sheetjs.xlsx"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > arrayBuffer< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* loop through the worksheet names in order */< / span >
< span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > forEach< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > name< / span > < span class = "pl-c1" > => < / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* generate HTML from the corresponding worksheets */< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > html< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > name< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* add to state */< / span >
< span class = "pl-smi" > this< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > name< span class = "pl-kos" > ,< / span > html < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c" > /* this state mantra is required for array updates to work */< / span >
< span class = "pl-en" > setup< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-k" > return< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > wb< / span > : < span class = "pl-en" > reactive< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > wb< / span > : < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > template< / span > : < span class = "pl-s" > `< / span >
< span class = "pl-s" > < div v-for="ws in wb.wb" :key="ws.name"> < / span >
< span class = "pl-s" > < h3> {{ ws.name }}< /h3> < / span >
< span class = "pl-s" > < div v-html="ws.html"> < /div> < / span >
< span class = "pl-s" > < /div> `< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > The < a href = "https://github.com/SheetJS/SheetJS/tree/master/demos/vue" > < code > vuejs< / code > demo< / a > includes more React examples.< / p >
< / details >
2022-03-03 09:23:56 +00:00
< h3 >
< a id = "user-content-generating-single-worksheet-snapshots" class = "anchor" href = "#generating-single-worksheet-snapshots" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Generating Single-Worksheet Snapshots< / h3 >
< p > The < code > sheet_to_*< / code > functions accept a worksheet object.< / p >
< p > < strong > API< / strong > < / p >
< p > < em > Generate a CSV from a single worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > csv< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_csv< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > This snapshot is designed to replicate the "CSV UTF8 (< code > .csv< / code > )" output type.
< a href = "#delimiter-separated-output" > "Delimiter-Separated Output"< / a > describes the
function and the optional < code > opts< / code > argument in more detail.< / p >
< p > < em > Generate "Text" from a single worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > txt< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_txt< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > opts< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > This snapshot is designed to replicate the "UTF16 Text (< code > .txt< / code > )" output type.
< a href = "#delimiter-separated-output" > "Delimiter-Separated Output"< / a > describes the
function and the optional < code > opts< / code > argument in more detail.< / p >
< p > < em > Generate a list of formulae from a single worksheet< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > fmla< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_formulae< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > This snapshot generates an array of entries representing the embedded formulae.
Array formulae are rendered in the form < code > range=formula< / code > while plain cells are
rendered in the form < code > cell=formula or value< / code > . String literals are prefixed with
an apostrophe < code > '< / code > , consistent with Excel's formula bar display.< / p >
< p > < a href = "#formulae-output" > "Formulae Output"< / a > describes the function in more detail.< / p >
2020-01-28 05:02:07 +00:00
< h2 >
< a id = "user-content-interface" class = "anchor" href = "#interface" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Interface< / h2 >
< p > < code > XLSX< / code > is the exposed variable in the browser and the exported node variable< / p >
< p > < code > XLSX.version< / code > is the version of the library (added by the build script).< / p >
2022-05-11 21:03:03 +00:00
< p > < code > XLSX.SSF< / code > is an embedded version of the < a href = "https://github.com/SheetJS/ssf" > format library< / a > .< / p >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-parsing-functions" class = "anchor" href = "#parsing-functions" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Parsing functions< / h3 >
< p > < code > XLSX.read(data, read_opts)< / code > attempts to parse < code > data< / code > .< / p >
< p > < code > XLSX.readFile(filename, read_opts)< / code > attempts to read < code > filename< / code > and parse.< / p >
< p > Parse options are described in the < a href = "#parsing-options" > Parsing Options< / a > section.< / p >
< h3 >
< a id = "user-content-writing-functions" class = "anchor" href = "#writing-functions" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Writing functions< / h3 >
< p > < code > XLSX.write(wb, write_opts)< / code > attempts to write the workbook < code > wb< / code > < / p >
< p > < code > XLSX.writeFile(wb, filename, write_opts)< / code > attempts to write < code > wb< / code > to < code > filename< / code > .
In browser-based environments, it will attempt to force a client-side download.< / p >
2022-05-11 21:03:03 +00:00
< p > < code > XLSX.writeFileAsync(filename, wb, o, cb)< / code > attempts to write < code > wb< / code > to < code > filename< / code > .
2020-01-28 05:02:07 +00:00
If < code > o< / code > is omitted, the writer will use the third argument as the callback.< / p >
< p > < code > XLSX.stream< / code > contains a set of streaming write functions.< / p >
< p > Write options are described in the < a href = "#writing-options" > Writing Options< / a > section.< / p >
< h3 >
< a id = "user-content-utilities" class = "anchor" href = "#utilities" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Utilities< / h3 >
< p > Utilities are available in the < code > XLSX.utils< / code > object and are described in the
< a href = "#utility-functions" > Utility Functions< / a > section:< / p >
2022-02-14 02:02:46 +00:00
< p > < strong > Constructing:< / strong > < / p >
< ul >
< li >
< code > book_new< / code > creates an empty workbook< / li >
< li >
< code > book_append_sheet< / code > adds a worksheet to a workbook< / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > < strong > Importing:< / strong > < / p >
< ul >
< li >
< code > aoa_to_sheet< / code > converts an array of arrays of JS data to a worksheet.< / li >
< li >
< code > json_to_sheet< / code > converts an array of JS objects to a worksheet.< / li >
< li >
< code > table_to_sheet< / code > converts a DOM TABLE element to a worksheet.< / li >
< li >
< code > sheet_add_aoa< / code > adds an array of arrays of JS data to an existing worksheet.< / li >
< li >
< code > sheet_add_json< / code > adds an array of JS objects to an existing worksheet.< / li >
< / ul >
< p > < strong > Exporting:< / strong > < / p >
< ul >
< li >
< code > sheet_to_json< / code > converts a worksheet object to an array of JSON objects.< / li >
< li >
< code > sheet_to_csv< / code > generates delimiter-separated-values output.< / li >
< li >
< code > sheet_to_txt< / code > generates UTF16 formatted text.< / li >
< li >
< code > sheet_to_html< / code > generates HTML output.< / li >
< li >
< code > sheet_to_formulae< / code > generates a list of the formulae (with value fallbacks).< / li >
< / ul >
< p > < strong > Cell and cell address manipulation:< / strong > < / p >
< ul >
< li >
< code > format_cell< / code > generates the text value for a cell (using number formats).< / li >
< li >
< code > encode_row / decode_row< / code > converts between 0-indexed rows and 1-indexed rows.< / li >
< li >
< code > encode_col / decode_col< / code > converts between 0-indexed columns and column names.< / li >
< li >
< code > encode_cell / decode_cell< / code > converts cell addresses.< / li >
< li >
< code > encode_range / decode_range< / code > converts cell ranges.< / li >
< / ul >
< h2 >
< a id = "user-content-common-spreadsheet-format" class = "anchor" href = "#common-spreadsheet-format" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Common Spreadsheet Format< / h2 >
2021-08-27 00:16:16 +00:00
< p > SheetJS conforms to the Common Spreadsheet Format (CSF):< / p >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-general-structures" class = "anchor" href = "#general-structures" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > General Structures< / h3 >
< p > Cell address objects are stored as < code > {c:C, r:R}< / code > where < code > C< / code > and < code > R< / code > are 0-indexed
column and row numbers, respectively. For example, the cell address < code > B5< / code > is
represented by the object < code > {c:1, r:4}< / code > .< / p >
< p > Cell range objects are stored as < code > {s:S, e:E}< / code > where < code > S< / code > is the first cell and
< code > E< / code > is the last cell in the range. The ranges are inclusive. For example, the
range < code > A3:B7< / code > is represented by the object < code > {s:{c:0, r:2}, e:{c:1, r:6}}< / code > .
Utility functions perform a row-major order walk traversal of a sheet range:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > var< / span > < span class = "pl-v" > R< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > s< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > r< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-v" > R< / span > < span class = "pl-c1" > < =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > r< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > ++< / span > < span class = "pl-v" > R< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > for< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > var< / span > < span class = "pl-v" > C< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > s< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-v" > C< / span > < span class = "pl-c1" > < =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c1" > ++< / span > < span class = "pl-v" > C< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > cell_address< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > c< / span > :< span class = "pl-v" > C< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > r< / span > :< span class = "pl-v" > R< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > /* if an A1-style address is needed, encode the address */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > cell_ref< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > encode_cell< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > cell_address< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-cell-object" class = "anchor" href = "#cell-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Cell Object< / h3 >
< p > Cell objects are plain JS objects with keys and values following the convention:< / p >
< table >
< thead >
< tr >
< th > Key< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > v< / code > < / td >
< td > raw value (see Data Types section for more info)< / td >
< / tr >
< tr >
< td > < code > w< / code > < / td >
< td > formatted text (if applicable)< / td >
< / tr >
< tr >
< td > < code > t< / code > < / td >
< td > type: < code > b< / code > Boolean, < code > e< / code > Error, < code > n< / code > Number, < code > d< / code > Date, < code > s< / code > Text, < code > z< / code > Stub< / td >
< / tr >
< tr >
< td > < code > f< / code > < / td >
< td > cell formula encoded as an A1-style string (if applicable)< / td >
< / tr >
< tr >
< td > < code > F< / code > < / td >
< td > range of enclosing array if formula is array formula (if applicable)< / td >
< / tr >
< tr >
2022-03-03 09:23:56 +00:00
< td > < code > D< / code > < / td >
< td > if true, array formula is dynamic (if applicable)< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td > < code > r< / code > < / td >
< td > rich text encoding (if applicable)< / td >
< / tr >
< tr >
< td > < code > h< / code > < / td >
< td > HTML rendering of the rich text (if applicable)< / td >
< / tr >
< tr >
< td > < code > c< / code > < / td >
< td > comments associated with the cell< / td >
< / tr >
< tr >
< td > < code > z< / code > < / td >
< td > number format string associated with the cell (if requested)< / td >
< / tr >
< tr >
< td > < code > l< / code > < / td >
< td > cell hyperlink object (< code > .Target< / code > holds link, < code > .Tooltip< / code > is tooltip)< / td >
< / tr >
< tr >
< td > < code > s< / code > < / td >
< td > the style/theme of the cell (if applicable)< / td >
< / tr >
< / tbody >
< / table >
< p > Built-in export utilities (such as the CSV exporter) will use the < code > w< / code > text if it
is available. To change a value, be sure to delete < code > cell.w< / code > (or set it to
< code > undefined< / code > ) before attempting to export. The utilities will regenerate the < code > w< / code >
text from the number format (< code > cell.z< / code > ) and the raw value if possible.< / p >
< p > The actual array formula is stored in the < code > f< / code > field of the first cell in the
array range. Other cells in the range will omit the < code > f< / code > field.< / p >
< h4 >
< a id = "user-content-data-types" class = "anchor" href = "#data-types" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Data Types< / h4 >
< p > The raw value is stored in the < code > v< / code > value property, interpreted based on the < code > t< / code >
type property. This separation allows for representation of numbers as well as
numeric text. There are 6 valid cell types:< / p >
< table >
< thead >
< tr >
< th align = "center" > Type< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "center" > < code > b< / code > < / td >
< td align = "left" > Boolean: value interpreted as JS < code > boolean< / code >
< / td >
< / tr >
< tr >
< td align = "center" > < code > e< / code > < / td >
< td align = "left" > Error: value is a numeric code and < code > w< / code > property stores common name **< / td >
< / tr >
< tr >
< td align = "center" > < code > n< / code > < / td >
< td align = "left" > Number: value is a JS < code > number< / code > **< / td >
< / tr >
< tr >
< td align = "center" > < code > d< / code > < / td >
< td align = "left" > Date: value is a JS < code > Date< / code > object or string to be parsed as Date **< / td >
< / tr >
< tr >
< td align = "center" > < code > s< / code > < / td >
< td align = "left" > Text: value interpreted as JS < code > string< / code > and written as text **< / td >
< / tr >
< tr >
< td align = "center" > < code > z< / code > < / td >
< td align = "left" > Stub: blank stub cell that is ignored by data processing utilities **< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Error values and interpretation< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th align = "right" > Value< / th >
< th align = "left" > Error Meaning< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "right" > < code > 0x00< / code > < / td >
< td align = "left" > < code > #NULL!< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x07< / code > < / td >
< td align = "left" > < code > #DIV/0!< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x0F< / code > < / td >
< td align = "left" > < code > #VALUE!< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x17< / code > < / td >
< td align = "left" > < code > #REF!< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x1D< / code > < / td >
< td align = "left" > < code > #NAME?< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x24< / code > < / td >
< td align = "left" > < code > #NUM!< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x2A< / code > < / td >
< td align = "left" > < code > #N/A< / code > < / td >
< / tr >
< tr >
< td align = "right" > < code > 0x2B< / code > < / td >
< td align = "left" > < code > #GETTING_DATA< / code > < / td >
< / tr >
< / tbody >
< / table >
< / details >
< p > Type < code > n< / code > is the Number type. This includes all forms of data that Excel stores
as numbers, such as dates/times and Boolean fields. Excel exclusively uses data
that can be fit in an IEEE754 floating point number, just like JS Number, so the
< code > v< / code > field holds the raw number. The < code > w< / code > field holds formatted text. Dates are
stored as numbers by default and converted with < code > XLSX.SSF.parse_date_code< / code > .< / p >
< p > Type < code > d< / code > is the Date type, generated only when the option < code > cellDates< / code > is passed.
Since JSON does not have a natural Date type, parsers are generally expected to
store ISO 8601 Date strings like you would get from < code > date.toISOString()< / code > . On
the other hand, writers and exporters should be able to handle date strings and
JS Date objects. Note that Excel disregards timezone modifiers and treats all
dates in the local timezone. The library does not correct for this error.< / p >
< p > Type < code > s< / code > is the String type. Values are explicitly stored as text. Excel will
interpret these cells as "number stored as text". Generated Excel files
automatically suppress that class of error, but other formats may elicit errors.< / p >
< p > Type < code > z< / code > represents blank stub cells. They are generated in cases where cells
have no assigned value but hold comments or other metadata. They are ignored by
the core library data processing utility functions. By default these cells are
not generated; the parser < code > sheetStubs< / code > option must be set to < code > true< / code > .< / p >
< h4 >
< a id = "user-content-dates" class = "anchor" href = "#dates" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Dates< / h4 >
< details >
< summary > < b > Excel Date Code details< / b > (click to show)< / summary >
< p > By default, Excel stores dates as numbers with a format code that specifies date
processing. For example, the date < code > 19-Feb-17< / code > is stored as the number < code > 42785< / code >
with a number format of < code > d-mmm-yy< / code > . The < code > SSF< / code > module understands number formats
and performs the appropriate conversion.< / p >
< p > XLSX also supports a special date type < code > d< / code > where the data is an ISO 8601 date
string. The formatter converts the date back to a number.< / p >
< p > The default behavior for all parsers is to generate number cells. Setting
< code > cellDates< / code > to true will force the generators to store dates.< / p >
< / details >
< details >
< summary > < b > Time Zones and Dates< / b > (click to show)< / summary >
< p > Excel has no native concept of universal time. All times are specified in the
local time zone. Excel limitations prevent specifying true absolute dates.< / p >
< p > Following Excel, this library treats all dates as relative to local time zone.< / p >
< / details >
< details >
< summary > < b > Epochs: 1900 and 1904< / b > (click to show)< / summary >
2021-09-12 09:16:01 +00:00
< p > Excel supports two epochs (January 1 1900 and January 1 1904).
2020-01-28 05:02:07 +00:00
The workbook's epoch can be determined by examining the workbook's
< code > wb.Workbook.WBProps.date1904< / code > property:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > !< / span > < span class = "pl-c1" > !< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Workbook< / span > < span class = "pl-c1" > ||< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > WBProps< / span > < span class = "pl-c1" > ||< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > date1904< / span > < span class = "pl-kos" > )< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
< a id = "user-content-sheet-objects" class = "anchor" href = "#sheet-objects" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Sheet Objects< / h3 >
< p > Each key that does not start with < code > !< / code > maps to a cell (using < code > A-1< / code > notation)< / p >
< p > < code > sheet[address]< / code > returns the cell object for the specified address.< / p >
< p > < strong > Special sheet keys (accessible as < code > sheet[key]< / code > , each starting with < code > !< / code > ):< / strong > < / p >
< ul >
< li >
< p > < code > sheet['!ref']< / code > : A-1 based range representing the sheet range. Functions that
work with sheets should use this parameter to determine the range. Cells that
are assigned outside of the range are not processed. In particular, when
writing a sheet by hand, cells outside of the range are not included< / p >
< p > Functions that handle sheets should test for the presence of < code > !ref< / code > field.
If the < code > !ref< / code > is omitted or is not a valid range, functions are free to treat
the sheet as empty or attempt to guess the range. The standard utilities that
ship with this library treat sheets as empty (for example, the CSV output is
empty string).< / p >
< p > When reading a worksheet with the < code > sheetRows< / code > property set, the ref parameter
will use the restricted range. The original range is set at < code > ws['!fullref']< / code > < / p >
< / li >
< li >
< p > < code > sheet['!margins']< / code > : Object representing the page margins. The default values
follow Excel's "normal" preset. Excel also has a "wide" and a "narrow" preset
but they are stored as raw measurements. The main properties are listed below:< / p >
< / li >
< / ul >
< details >
< summary > < b > Page margin details< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th > key< / th >
< th > description< / th >
< th align = "left" > "normal"< / th >
< th align = "left" > "wide"< / th >
< th align = "left" > "narrow"< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > left< / code > < / td >
< td > left margin (inches)< / td >
< td align = "left" > < code > 0.7< / code > < / td >
< td align = "left" > < code > 1.0< / code > < / td >
< td align = "left" > < code > 0.25< / code > < / td >
< / tr >
< tr >
< td > < code > right< / code > < / td >
< td > right margin (inches)< / td >
< td align = "left" > < code > 0.7< / code > < / td >
< td align = "left" > < code > 1.0< / code > < / td >
< td align = "left" > < code > 0.25< / code > < / td >
< / tr >
< tr >
< td > < code > top< / code > < / td >
< td > top margin (inches)< / td >
< td align = "left" > < code > 0.75< / code > < / td >
< td align = "left" > < code > 1.0< / code > < / td >
< td align = "left" > < code > 0.75< / code > < / td >
< / tr >
< tr >
< td > < code > bottom< / code > < / td >
< td > bottom margin (inches)< / td >
< td align = "left" > < code > 0.75< / code > < / td >
< td align = "left" > < code > 1.0< / code > < / td >
< td align = "left" > < code > 0.75< / code > < / td >
< / tr >
< tr >
< td > < code > header< / code > < / td >
< td > header margin (inches)< / td >
< td align = "left" > < code > 0.3< / code > < / td >
< td align = "left" > < code > 0.5< / code > < / td >
< td align = "left" > < code > 0.3< / code > < / td >
< / tr >
< tr >
< td > < code > footer< / code > < / td >
< td > footer margin (inches)< / td >
< td align = "left" > < code > 0.3< / code > < / td >
< td align = "left" > < code > 0.5< / code > < / td >
< td align = "left" > < code > 0.3< / code > < / td >
< / tr >
< / tbody >
< / table >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* Set worksheet sheet to "normal" */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!margins"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > left< / span > :< span class = "pl-c1" > 0.7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > right< / span > :< span class = "pl-c1" > 0.7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > top< / span > :< span class = "pl-c1" > 0.75< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bottom< / span > :< span class = "pl-c1" > 0.75< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 0.3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > footer< / span > :< span class = "pl-c1" > 0.3< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* Set worksheet sheet to "wide" */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!margins"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > left< / span > :< span class = "pl-c1" > 1.0< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > right< / span > :< span class = "pl-c1" > 1.0< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > top< / span > :< span class = "pl-c1" > 1.0< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bottom< / span > :< span class = "pl-c1" > 1.0< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 0.5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > footer< / span > :< span class = "pl-c1" > 0.5< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* Set worksheet sheet to "narrow" */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!margins"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > left< / span > :< span class = "pl-c1" > 0.25< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > right< / span > :< span class = "pl-c1" > 0.25< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > top< / span > :< span class = "pl-c1" > 0.75< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > bottom< / span > :< span class = "pl-c1" > 0.75< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 0.3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > footer< / span > :< span class = "pl-c1" > 0.3< / span > < span class = "pl-kos" > }< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h4 >
< a id = "user-content-worksheet-object" class = "anchor" href = "#worksheet-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Worksheet Object< / h4 >
< p > In addition to the base sheet keys, worksheets also add:< / p >
< ul >
< li >
< p > < code > ws['!cols']< / code > : array of column properties objects. Column widths are actually
stored in files in a normalized manner, measured in terms of the "Maximum
Digit Width" (the largest width of the rendered digits 0-9, in pixels). When
parsed, the column objects store the pixel width in the < code > wpx< / code > field, character
width in the < code > wch< / code > field, and the maximum digit width in the < code > MDW< / code > field.< / p >
< / li >
< li >
< p > < code > ws['!rows']< / code > : array of row properties objects as explained later in the docs.
Each row object encodes properties including row height and visibility.< / p >
< / li >
< li >
< p > < code > ws['!merges']< / code > : array of range objects corresponding to the merged cells in
the worksheet. Plain text formats do not support merge cells. CSV export
will write all cells in the merge range if they exist, so be sure that only
the first cell (upper-left) in the range is set.< / p >
< / li >
< li >
2021-08-27 00:16:16 +00:00
< p > < code > ws['!outline']< / code > : configure how outlines should behave. Options default to
the default settings in Excel 2019:< / p >
< / li >
< / ul >
< table >
< thead >
< tr >
< th align = "left" > key< / th >
< th align = "left" > Excel feature< / th >
< th align = "left" > default< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > above< / code > < / td >
< td align = "left" > Uncheck "Summary rows below detail"< / td >
< td align = "left" > < code > false< / code > < / td >
< / tr >
< tr >
< td align = "left" > < code > left< / code > < / td >
< td align = "left" > Uncheck "Summary rows to the right of detail"< / td >
< td align = "left" > < code > false< / code > < / td >
< / tr >
< / tbody >
< / table >
< ul >
< li >
< code > ws['!protect']< / code > : object of write sheet protection properties. The < code > password< / code >
2020-01-28 05:02:07 +00:00
key specifies the password for formats that support password-protected sheets
(XLSX/XLSB/XLS). The writer uses the XOR obfuscation method. The following
keys control the sheet protection -- set to < code > false< / code > to enable a feature when
2021-08-27 00:16:16 +00:00
sheet is locked or set to < code > true< / code > to disable a feature:< / li >
2020-01-28 05:02:07 +00:00
< / ul >
< details >
< summary > < b > Worksheet Protection Details< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th align = "left" > key< / th >
< th align = "left" > feature (true=disabled / false=enabled)< / th >
< th align = "left" > default< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > selectLockedCells< / code > < / td >
< td align = "left" > Select locked cells< / td >
< td align = "left" > enabled< / td >
< / tr >
< tr >
< td align = "left" > < code > selectUnlockedCells< / code > < / td >
< td align = "left" > Select unlocked cells< / td >
< td align = "left" > enabled< / td >
< / tr >
< tr >
< td align = "left" > < code > formatCells< / code > < / td >
< td align = "left" > Format cells< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > formatColumns< / code > < / td >
< td align = "left" > Format columns< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > formatRows< / code > < / td >
< td align = "left" > Format rows< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > insertColumns< / code > < / td >
< td align = "left" > Insert columns< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > insertRows< / code > < / td >
< td align = "left" > Insert rows< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > insertHyperlinks< / code > < / td >
< td align = "left" > Insert hyperlinks< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > deleteColumns< / code > < / td >
< td align = "left" > Delete columns< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > deleteRows< / code > < / td >
< td align = "left" > Delete rows< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > sort< / code > < / td >
< td align = "left" > Sort< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > autoFilter< / code > < / td >
< td align = "left" > Filter< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > pivotTables< / code > < / td >
< td align = "left" > Use PivotTable reports< / td >
< td align = "left" > disabled< / td >
< / tr >
< tr >
< td align = "left" > < code > objects< / code > < / td >
< td align = "left" > Edit objects< / td >
< td align = "left" > enabled< / td >
< / tr >
< tr >
< td align = "left" > < code > scenarios< / code > < / td >
< td align = "left" > Edit scenarios< / td >
< td align = "left" > enabled< / td >
< / tr >
< / tbody >
< / table >
< / details >
< ul >
< li >
< code > ws['!autofilter']< / code > : AutoFilter object following the schema:< / li >
< / ul >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-k" > type< / span > < span class = "pl-smi" > AutoFilter< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c1" > ref< / span > :< span class = "pl-smi" > string< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // A-1 based range representing the AutoFilter table range< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< h4 >
< a id = "user-content-chartsheet-object" class = "anchor" href = "#chartsheet-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Chartsheet Object< / h4 >
< p > Chartsheets are represented as standard sheets. They are distinguished with the
< code > !type< / code > property set to < code > "chart"< / code > .< / p >
< p > The underlying data and < code > !ref< / code > refer to the cached data in the chartsheet. The
first row of the chartsheet is the underlying header.< / p >
< h4 >
< a id = "user-content-macrosheet-object" class = "anchor" href = "#macrosheet-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Macrosheet Object< / h4 >
< p > Macrosheets are represented as standard sheets. They are distinguished with the
< code > !type< / code > property set to < code > "macro"< / code > .< / p >
< h4 >
< a id = "user-content-dialogsheet-object" class = "anchor" href = "#dialogsheet-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Dialogsheet Object< / h4 >
< p > Dialogsheets are represented as standard sheets. They are distinguished with the
< code > !type< / code > property set to < code > "dialog"< / code > .< / p >
< h3 >
< a id = "user-content-workbook-object" class = "anchor" href = "#workbook-object" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Workbook Object< / h3 >
< p > < code > workbook.SheetNames< / code > is an ordered list of the sheets in the workbook< / p >
< p > < code > wb.Sheets[sheetname]< / code > returns an object representing the worksheet.< / p >
< p > < code > wb.Props< / code > is an object storing the standard properties. < code > wb.Custprops< / code > stores
custom properties. Since the XLS standard properties deviate from the XLSX
standard, XLS parsing stores core properties in both places.< / p >
< p > < code > wb.Workbook< / code > stores < a href = "#workbook-level-attributes" > workbook-level attributes< / a > .< / p >
< h4 >
< a id = "user-content-workbook-file-properties" class = "anchor" href = "#workbook-file-properties" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Workbook File Properties< / h4 >
< p > The various file formats use different internal names for file properties. The
workbook < code > Props< / code > object normalizes the names:< / p >
< details >
< summary > < b > File Properties< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th align = "left" > JS Name< / th >
< th align = "left" > Excel Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > Title< / code > < / td >
< td align = "left" > Summary tab "Title"< / td >
< / tr >
< tr >
< td align = "left" > < code > Subject< / code > < / td >
< td align = "left" > Summary tab "Subject"< / td >
< / tr >
< tr >
< td align = "left" > < code > Author< / code > < / td >
< td align = "left" > Summary tab "Author"< / td >
< / tr >
< tr >
< td align = "left" > < code > Manager< / code > < / td >
< td align = "left" > Summary tab "Manager"< / td >
< / tr >
< tr >
< td align = "left" > < code > Company< / code > < / td >
< td align = "left" > Summary tab "Company"< / td >
< / tr >
< tr >
< td align = "left" > < code > Category< / code > < / td >
< td align = "left" > Summary tab "Category"< / td >
< / tr >
< tr >
< td align = "left" > < code > Keywords< / code > < / td >
< td align = "left" > Summary tab "Keywords"< / td >
< / tr >
< tr >
< td align = "left" > < code > Comments< / code > < / td >
< td align = "left" > Summary tab "Comments"< / td >
< / tr >
< tr >
< td align = "left" > < code > LastAuthor< / code > < / td >
< td align = "left" > Statistics tab "Last saved by"< / td >
< / tr >
< tr >
< td align = "left" > < code > CreatedDate< / code > < / td >
< td align = "left" > Statistics tab "Created"< / td >
< / tr >
< / tbody >
< / table >
< / details >
< p > For example, to set the workbook title property:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Props< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Props< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Props< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Title< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "Insert Title Here"< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Custom properties are added in the workbook < code > Custprops< / code > object:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Custprops< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Custprops< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Custprops< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Custom Property"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "Custom Value"< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Writers will process the < code > Props< / code > key of the options object:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* force the Author to be "SheetJS" */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > write< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Props< / span > :< span class = "pl-kos" > {< / span > < span class = "pl-c1" > Author< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-workbook-level-attributes" class = "anchor" href = "#workbook-level-attributes" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Workbook-Level Attributes< / h3 >
< p > < code > wb.Workbook< / code > stores workbook-level attributes.< / p >
< h4 >
< a id = "user-content-defined-names" class = "anchor" href = "#defined-names" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Defined Names< / h4 >
2022-05-11 21:03:03 +00:00
< details >
< summary > < b > Format Support< / b > (click to show)< / summary >
< p > < strong > Defined Names< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK< / p >
< p > < strong > Unicode Defined Names< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML< / p >
< p > < strong > Defined Name Comment< / strong > : XLSX/M, XLSB, BIFF8 XLS< / p >
< / details >
2020-01-28 05:02:07 +00:00
< p > < code > wb.Workbook.Names< / code > is an array of defined name objects which have the keys:< / p >
< details >
< summary > < b > Defined Name Properties< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th align = "left" > Key< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > Sheet< / code > < / td >
< td align = "left" > Name scope. Sheet Index (0 = first sheet) or < code > null< / code > (Workbook)< / td >
< / tr >
< tr >
< td align = "left" > < code > Name< / code > < / td >
< td align = "left" > Case-sensitive name. Standard rules apply **< / td >
< / tr >
< tr >
< td align = "left" > < code > Ref< / code > < / td >
< td align = "left" > A1-style Reference (< code > "Sheet1!$A$1:$D$20"< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > Comment< / code > < / td >
< td align = "left" > Comment (only applicable for XLS/XLSX/XLSB)< / td >
< / tr >
< / tbody >
< / table >
< / details >
< p > Excel allows two sheet-scoped defined names to share the same name. However, a
sheet-scoped name cannot collide with a workbook-scope name. Workbook writers
may not enforce this constraint.< / p >
< h4 >
< a id = "user-content-workbook-views" class = "anchor" href = "#workbook-views" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Workbook Views< / h4 >
< p > < code > wb.Workbook.Views< / code > is an array of workbook view objects which have the keys:< / p >
< table >
< thead >
< tr >
< th align = "left" > Key< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > RTL< / code > < / td >
< td align = "left" > If true, display right-to-left< / td >
< / tr >
< / tbody >
< / table >
< h4 >
< a id = "user-content-miscellaneous-workbook-properties" class = "anchor" href = "#miscellaneous-workbook-properties" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Miscellaneous Workbook Properties< / h4 >
< p > < code > wb.Workbook.WBProps< / code > holds other workbook properties:< / p >
< table >
< thead >
< tr >
< th align = "left" > Key< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > CodeName< / code > < / td >
< td align = "left" > < a href = "#vba-and-macros" > VBA Project Workbook Code Name< / a > < / td >
< / tr >
< tr >
< td align = "left" > < code > date1904< / code > < / td >
< td align = "left" > epoch: 0/false for 1900 system, 1/true for 1904< / td >
< / tr >
< tr >
< td align = "left" > < code > filterPrivacy< / code > < / td >
< td align = "left" > Warn or strip personally identifying info on save< / td >
< / tr >
< / tbody >
< / table >
< h3 >
< a id = "user-content-document-features" class = "anchor" href = "#document-features" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Document Features< / h3 >
< p > Even for basic features like date storage, the official Excel formats store the
same content in different ways. The parsers are expected to convert from the
underlying file format representation to the Common Spreadsheet Format. Writers
are expected to convert from CSF back to the underlying file format.< / p >
< h4 >
< a id = "user-content-formulae" class = "anchor" href = "#formulae" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Formulae< / h4 >
< p > The A1-style formula string is stored in the < code > f< / code > field. Even though different
file formats store the formulae in different ways, the formats are translated.
Even though some formats store formulae with a leading equal sign, CSF formulae
do not start with < code > =< / code > .< / p >
< details >
2022-03-03 09:23:56 +00:00
< summary > < b > Formulae File Format Support< / b > (click to show)< / summary >
2020-01-28 05:02:07 +00:00
< table >
< thead >
< tr >
< th align = "left" > Storage Representation< / th >
< th align = "left" > Formats< / th >
< th align = "center" > Read< / th >
< th align = "center" > Write< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > A1-style strings< / td >
< td align = "left" > XLSX< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > RC-style strings< / td >
< td align = "left" > XLML and plain text< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > BIFF Parsed formulae< / td >
< td align = "left" > XLSB and all XLS formats< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > OpenFormula formulae< / td >
< td align = "left" > ODS/FODS/UOS< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< / tr >
< tr >
< td align = "left" > Lotus Parsed formulae< / td >
< td align = "left" > All Lotus WK_ formats< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< / tbody >
< / table >
< p > Since Excel prohibits named cells from colliding with names of A1 or RC style
cell references, a (not-so-simple) regex conversion is possible. BIFF Parsed
2022-02-01 06:12:44 +00:00
formulae and Lotus Parsed formulae have to be explicitly unwound. OpenFormula
formulae can be converted with regular expressions.< / p >
2022-03-03 09:23:56 +00:00
< p > Shared formulae are decompressed and each cell has the formula corresponding to
its cell. Writers generally do not attempt to generate shared formulae.< / p >
< / details >
< p > < strong > Single-Cell Formulae< / strong > < / p >
< p > For simple formulae, the < code > f< / code > key of the desired cell can be set to the actual
formula text. This worksheet represents < code > A1=1< / code > , < code > A2=2< / code > , and < code > A3=A1+A2< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-s" > "!ref"< / span > : < span class = "pl-s" > "A1:A3"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > A1< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > A2< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 2< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > A3< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > :< span class = "pl-s" > 'A1+A2'< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Utilities like < code > aoa_to_sheet< / code > will accept cell objects in lieu of values:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // A1< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // A2< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > : < span class = "pl-s" > "n"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > : < span class = "pl-s" > "A1+A2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c" > // A3< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Cells with formula entries but no value will be serialized in a way that Excel
and other spreadsheet tools will recognize. This library will not automatically
compute formula results! For example, the following worksheet will include the
< code > BESSELJ< / code > function but the result will not be available in JavaScript:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 3.14159< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // Row "1"< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > :< span class = "pl-s" > 'BESSELJ(A1,B1)'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c" > // Row "2" will be calculated on file open< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
< p > If the actual results are needed in JS, < a href = "https://sheetjs.com/pro" rel = "nofollow" > SheetJS Pro< / a >
offers a formula calculator component for evaluating expressions, updating
values and dependent cells, and refreshing entire workbooks.< / p >
< p > < strong > Array Formulae< / strong > < / p >
< p > < em > Assign an array formula< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > formula< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Array formulae are stored in the top-left cell of the array block. All cells
of an array formula have a < code > F< / code > field corresponding to the range. A single-cell
formula can be distinguished from a plain formula by the presence of < code > F< / code > field.< / p >
< p > For example, setting the cell < code > C1< / code > to the array formula < code > {=SUM(A1:A3*B1:B3)}< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // API function< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "SUM(A1:A3*B1:B3)"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // ... OR raw operations< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'C1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > : < span class = "pl-s" > "SUM(A1:A3*B1:B3)"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "C1:C1"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > For a multi-cell array formula, every cell has the same array range but only the
first cell specifies the formula. Consider < code > D1:D3=A1:A3*B1:B3< / code > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // API function< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "D1:D3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "A1:A3*B1:B3"< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // ... OR raw operations< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'D1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "D1:D3"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > :< span class = "pl-s" > "A1:A3*B1:B3"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'D2'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "D1:D3"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'D3'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > 'n'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "D1:D3"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Utilities and writers are expected to check for the presence of a < code > F< / code > field and
ignore any possible formula element < code > f< / code > in cells other than the starting cell.
They are not expected to perform validation of the formulae!< / p >
< p > < strong > Dynamic Array Formulae< / strong > < / p >
< p > < em > Assign a dynamic array formula< / em > < / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > formula< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Released in 2020, Dynamic Array Formulae are supported in the XLSX/XLSM and XLSB
file formats. They are represented like normal array formulae but have special
cell metadata indicating that the formula should be allowed to adjust the range.< / p >
< p > An array formula can be marked as dynamic by setting the cell's < code > D< / code > property to
true. The < code > F< / code > range is expected but can be the set to the current cell:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // API function< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "_xlfn.UNIQUE(A1:A3)"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // ... OR raw operations< / span >
< span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'C1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > : < span class = "pl-s" > "s"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > f< / span > : < span class = "pl-s" > "_xlfn.UNIQUE(A1:A3)"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // dynamic< / span > < / pre > < / div >
< p > < strong > Localization with Function Names< / strong > < / p >
< p > SheetJS operates at the file level. Excel stores formula expressions using the
English (United States) function names. For non-English users, Excel uses a
localized set of function names.< / p >
< p > For example, when the computer language and region is set to French (France),
Excel interprets < code > =SOMME(A1:C3)< / code > as if < code > SOMME< / code > is the < code > SUM< / code > function. However,
in the actual file, Excel stores < code > SUM(A1:C3)< / code > .< / p >
< p > < strong > Prefixed "Future Functions"< / strong > < / p >
< p > Functions introduced in newer versions of Excel are prefixed with < code > _xlfn.< / code > when
stored in files. When writing formula expressions using these functions, the
prefix is required for maximal compatibility:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > // Broadest compatibility< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "_xlfn.UNIQUE(A1:A3)"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // Can cause errors in spreadsheet software< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_set_array_formula< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "UNIQUE(A1:A3)"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > When reading a file, the < code > xlfn< / code > option preserves the prefixes.< / p >
< details >
< summary > < b > Functions requiring `_xlfn.` prefix< / b > (click to show)< / summary >
< p > This list is growing with each Excel release.< / p >
< pre > < code > ACOT
ACOTH
AGGREGATE
ARABIC
BASE
BETA.DIST
BETA.INV
BINOM.DIST
BINOM.DIST.RANGE
BINOM.INV
BITAND
BITLSHIFT
BITOR
BITRSHIFT
BITXOR
BYCOL
BYROW
CEILING.MATH
CEILING.PRECISE
CHISQ.DIST
CHISQ.DIST.RT
CHISQ.INV
CHISQ.INV.RT
CHISQ.TEST
COMBINA
CONFIDENCE.NORM
CONFIDENCE.T
COT
COTH
COVARIANCE.P
COVARIANCE.S
CSC
CSCH
DAYS
DECIMAL
ERF.PRECISE
ERFC.PRECISE
EXPON.DIST
F.DIST
F.DIST.RT
F.INV
F.INV.RT
F.TEST
FIELDVALUE
FILTERXML
FLOOR.MATH
FLOOR.PRECISE
FORMULATEXT
GAMMA
GAMMA.DIST
GAMMA.INV
GAMMALN.PRECISE
GAUSS
HYPGEOM.DIST
IFNA
IMCOSH
IMCOT
IMCSC
IMCSCH
IMSEC
IMSECH
IMSINH
IMTAN
ISFORMULA
ISOMITTED
ISOWEEKNUM
LAMBDA
LET
LOGNORM.DIST
LOGNORM.INV
MAKEARRAY
MAP
MODE.MULT
MODE.SNGL
MUNIT
NEGBINOM.DIST
NORM.DIST
NORM.INV
NORM.S.DIST
NORM.S.INV
NUMBERVALUE
PDURATION
PERCENTILE.EXC
PERCENTILE.INC
PERCENTRANK.EXC
PERCENTRANK.INC
PERMUTATIONA
PHI
POISSON.DIST
QUARTILE.EXC
QUARTILE.INC
QUERYSTRING
RANDARRAY
RANK.AVG
RANK.EQ
REDUCE
RRI
SCAN
SEC
SECH
SEQUENCE
SHEET
SHEETS
SKEW.P
SORTBY
STDEV.P
STDEV.S
T.DIST
T.DIST.2T
T.DIST.RT
T.INV
T.INV.2T
T.TEST
UNICHAR
UNICODE
UNIQUE
VAR.P
VAR.S
WEBSERVICE
WEIBULL.DIST
XLOOKUP
XOR
Z.TEST
< / code > < / pre >
2020-01-28 05:02:07 +00:00
< / details >
< h4 >
2022-02-14 02:02:46 +00:00
< a id = "user-content-row-and-column-properties" class = "anchor" href = "#row-and-column-properties" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Row and Column Properties< / h4 >
< details >
< summary > < b > Format Support< / b > (click to show)< / summary >
< p > < strong > Row Properties< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK, DOM, ODS< / p >
< p > < strong > Column Properties< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML, SYLK, DOM< / p >
< / details >
< p > Row and Column properties are not extracted by default when reading from a file
and are not persisted by default when writing to a file. The option
< code > cellStyles: true< / code > must be passed to the relevant read or write function.< / p >
< p > < em > Column Properties< / em > < / p >
2020-01-28 05:02:07 +00:00
< p > The < code > !cols< / code > array in each worksheet, if present, is a collection of < code > ColInfo< / code >
objects which have the following properties:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-k" > type< / span > < span class = "pl-smi" > ColInfo< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* visibility */< / span >
< span class = "pl-c1" > hidden< / span > ?: < span class = "pl-smi" > boolean< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // if true, the column is hidden< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* column width is specified in one of the following ways: */< / span >
< span class = "pl-c1" > wpx< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // width in screen pixels< / span >
< span class = "pl-c1" > width< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // width in Excel's "Max Digit Width", width*256 is integral< / span >
< span class = "pl-c1" > wch< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // width in characters< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* other fields for preserving features from files */< / span >
2022-02-01 06:12:44 +00:00
< span class = "pl-c1" > level< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // 0-indexed outline / group level< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > MDW< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // Excel's "Max Digit Width" unit, always integral< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-02-14 02:02:46 +00:00
< p > < em > Row Properties< / em > < / p >
< p > The < code > !rows< / code > array in each worksheet, if present, is a collection of < code > RowInfo< / code >
objects which have the following properties:< / p >
< div class = "highlight highlight-source-ts" > < pre > < span class = "pl-k" > type< / span > < span class = "pl-smi" > RowInfo< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c" > /* visibility */< / span >
< span class = "pl-c1" > hidden< / span > ?: < span class = "pl-smi" > boolean< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // if true, the row is hidden< / span >
< span class = "pl-c" > /* row height is specified in one of the following ways: */< / span >
< span class = "pl-c1" > hpx< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // height in screen pixels< / span >
< span class = "pl-c1" > hpt< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // height in points< / span >
< span class = "pl-c1" > level< / span > ?: < span class = "pl-smi" > number< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // 0-indexed outline / group level< / span >
< span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Outline / Group Levels Convention< / em > < / p >
< p > The Excel UI displays the base outline level as < code > 1< / code > and the max level as < code > 8< / code > .
Following JS conventions, SheetJS uses 0-indexed outline levels wherein the base
outline level is < code > 0< / code > and the max level is < code > 7< / code > .< / p >
2020-01-28 05:02:07 +00:00
< details >
< summary > < b > Why are there three width types?< / b > (click to show)< / summary >
< p > There are three different width types corresponding to the three different ways
spreadsheets store column widths:< / p >
< p > SYLK and other plain text formats use raw character count. Contemporaneous tools
like Visicalc and Multiplan were character based. Since the characters had the
same width, it sufficed to store a count. This tradition was continued into the
BIFF formats.< / p >
< p > SpreadsheetML (2003) tried to align with HTML by standardizing on screen pixel
count throughout the file. Column widths, row heights, and other measures use
pixels. When the pixel and character counts do not align, Excel rounds values.< / p >
< p > XLSX internally stores column widths in a nebulous "Max Digit Width" form. The
Max Digit Width is the width of the largest digit when rendered (generally the
"0" character is the widest). The internal width must be an integer multiple of
the the width divided by 256. ECMA-376 describes a formula for converting
between pixels and the internal width. This represents a hybrid approach.< / p >
< p > Read functions attempt to populate all three properties. Write functions will
try to cycle specified values to the desired type. In order to avoid potential
conflicts, manipulation should delete the other properties first. For example,
when changing the pixel width, delete the < code > wch< / code > and < code > width< / code > properties.< / p >
< / details >
< details >
< summary > < b > Implementation details< / b > (click to show)< / summary >
2022-02-14 02:02:46 +00:00
< p > < em > Row Heights< / em > < / p >
< p > Excel internally stores row heights in points. The default resolution is 72 DPI
or 96 PPI, so the pixel and point size should agree. For different resolutions
they may not agree, so the library separates the concepts.< / p >
< p > Even though all of the information is made available, writers are expected to
follow the priority order:< / p >
< ol >
< li > use < code > hpx< / code > pixel height if available< / li >
< li > use < code > hpt< / code > point height if available< / li >
< / ol >
< p > < em > Column Widths< / em > < / p >
2020-01-28 05:02:07 +00:00
< p > Given the constraints, it is possible to determine the MDW without actually
inspecting the font! The parsers guess the pixel width by converting from width
to pixels and back, repeating for all possible MDW and selecting the MDW that
minimizes the error. XLML actually stores the pixel width, so the guess works
in the opposite direction.< / p >
< p > Even though all of the information is made available, writers are expected to
follow the priority order:< / p >
< ol >
< li > use < code > width< / code > field if available< / li >
< li > use < code > wpx< / code > pixel width if available< / li >
< li > use < code > wch< / code > character count if available< / li >
< / ol >
< / details >
< h4 >
< a id = "user-content-number-formats" class = "anchor" href = "#number-formats" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Number Formats< / h4 >
< p > The < code > cell.w< / code > formatted text for each cell is produced from < code > cell.v< / code > and < code > cell.z< / code >
format. If the format is not specified, the Excel < code > General< / code > format is used.
The format can either be specified as a string or as an index into the format
table. Parsers are expected to populate < code > workbook.SSF< / code > with the number format
table. Writers are expected to serialize the table.< / p >
< p > Custom tools should ensure that the local table has each used format string
somewhere in the table. Excel convention mandates that the custom formats start
at index 164. The following example creates a custom format from scratch:< / p >
< details >
< summary > < b > New worksheet with custom format< / b > (click to show)< / summary >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-c1" > SheetNames< / span > : < span class = "pl-kos" > [< / span > < span class = "pl-s" > "Sheet1"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > Sheets< / span > : < span class = "pl-kos" > {< / span >
< span class = "pl-c1" > Sheet1< / span > : < span class = "pl-kos" > {< / span >
< span class = "pl-s" > "!ref"< / span > :< span class = "pl-s" > "A1:C1"< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-c1" > A1< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "n"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 10000< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- General format< / span >
< span class = "pl-c1" > B1< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "n"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 10000< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > z< / span > : < span class = "pl-s" > "0%"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- Builtin format< / span >
< span class = "pl-c1" > C1< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "n"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > v< / span > :< span class = "pl-c1" > 10000< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > z< / span > : < span class = "pl-s" > "\"T\"\ #0.00"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-c" > // < -- Custom format< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< p > The rules are slightly different from how Excel displays custom number formats.
In particular, literal characters must be wrapped in double quotes or preceded
by a backslash. For more info, see the Excel documentation article
< code > Create or delete a custom number format< / code > or ECMA-376 18.8.31 (Number Formats)< / p >
< details >
< summary > < b > Default Number Formats< / b > (click to show)< / summary >
< p > The default formats are listed in ECMA-376 18.8.30:< / p >
< table >
< thead >
< tr >
< th align = "right" > ID< / th >
< th align = "left" > Format< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "right" > 0< / td >
< td align = "left" > < code > General< / code > < / td >
< / tr >
< tr >
< td align = "right" > 1< / td >
< td align = "left" > < code > 0< / code > < / td >
< / tr >
< tr >
< td align = "right" > 2< / td >
< td align = "left" > < code > 0.00< / code > < / td >
< / tr >
< tr >
< td align = "right" > 3< / td >
< td align = "left" > < code > #,##0< / code > < / td >
< / tr >
< tr >
< td align = "right" > 4< / td >
< td align = "left" > < code > #,##0.00< / code > < / td >
< / tr >
< tr >
< td align = "right" > 9< / td >
< td align = "left" > < code > 0%< / code > < / td >
< / tr >
< tr >
< td align = "right" > 10< / td >
< td align = "left" > < code > 0.00%< / code > < / td >
< / tr >
< tr >
< td align = "right" > 11< / td >
< td align = "left" > < code > 0.00E+00< / code > < / td >
< / tr >
< tr >
< td align = "right" > 12< / td >
< td align = "left" > < code > # ?/?< / code > < / td >
< / tr >
< tr >
< td align = "right" > 13< / td >
< td align = "left" > < code > # ??/??< / code > < / td >
< / tr >
< tr >
< td align = "right" > 14< / td >
< td align = "left" >
< code > m/d/yy< / code > (see below)< / td >
< / tr >
< tr >
< td align = "right" > 15< / td >
< td align = "left" > < code > d-mmm-yy< / code > < / td >
< / tr >
< tr >
< td align = "right" > 16< / td >
< td align = "left" > < code > d-mmm< / code > < / td >
< / tr >
< tr >
< td align = "right" > 17< / td >
< td align = "left" > < code > mmm-yy< / code > < / td >
< / tr >
< tr >
< td align = "right" > 18< / td >
< td align = "left" > < code > h:mm AM/PM< / code > < / td >
< / tr >
< tr >
< td align = "right" > 19< / td >
< td align = "left" > < code > h:mm:ss AM/PM< / code > < / td >
< / tr >
< tr >
< td align = "right" > 20< / td >
< td align = "left" > < code > h:mm< / code > < / td >
< / tr >
< tr >
< td align = "right" > 21< / td >
< td align = "left" > < code > h:mm:ss< / code > < / td >
< / tr >
< tr >
< td align = "right" > 22< / td >
< td align = "left" > < code > m/d/yy h:mm< / code > < / td >
< / tr >
< tr >
< td align = "right" > 37< / td >
< td align = "left" > < code > #,##0 ;(#,##0)< / code > < / td >
< / tr >
< tr >
< td align = "right" > 38< / td >
< td align = "left" > < code > #,##0 ;[Red](#,##0)< / code > < / td >
< / tr >
< tr >
< td align = "right" > 39< / td >
< td align = "left" > < code > #,##0.00;(#,##0.00)< / code > < / td >
< / tr >
< tr >
< td align = "right" > 40< / td >
< td align = "left" > < code > #,##0.00;[Red](#,##0.00)< / code > < / td >
< / tr >
< tr >
< td align = "right" > 45< / td >
< td align = "left" > < code > mm:ss< / code > < / td >
< / tr >
< tr >
< td align = "right" > 46< / td >
< td align = "left" > < code > [h]:mm:ss< / code > < / td >
< / tr >
< tr >
< td align = "right" > 47< / td >
< td align = "left" > < code > mmss.0< / code > < / td >
< / tr >
< tr >
< td align = "right" > 48< / td >
< td align = "left" > < code > ##0.0E+0< / code > < / td >
< / tr >
< tr >
< td align = "right" > 49< / td >
< td align = "left" > < code > @< / code > < / td >
< / tr >
< / tbody >
< / table >
< / details >
< p > Format 14 (< code > m/d/yy< / code > ) is localized by Excel: even though the file specifies that
number format, it will be drawn differently based on system settings. It makes
sense when the producer and consumer of files are in the same locale, but that
is not always the case over the Internet. To get around this ambiguity, parse
functions accept the < code > dateNF< / code > option to override the interpretation of that
specific format string.< / p >
< h4 >
< a id = "user-content-hyperlinks" class = "anchor" href = "#hyperlinks" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Hyperlinks< / h4 >
2022-02-01 06:12:44 +00:00
< details >
< summary > < b > Format Support< / b > (click to show)< / summary >
< p > < strong > Cell Hyperlinks< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML, ODS< / p >
< p > < strong > Tooltips< / strong > : XLSX/M, XLSB, BIFF8 XLS, XLML< / p >
< / details >
2020-01-28 05:02:07 +00:00
< p > Hyperlinks are stored in the < code > l< / code > key of cell objects. The < code > Target< / code > field of the
hyperlink object is the target of the link, including the URI fragment. Tooltips
are stored in the < code > Tooltip< / code > field and are displayed when you move your mouse
over the text.< / p >
< p > For example, the following snippet creates a link from cell < code > A3< / code > to
2021-09-12 09:16:01 +00:00
< a href = "https://sheetjs.com" rel = "nofollow" > https://sheetjs.com< / a > with the tip < code > "Find us @ SheetJS.com!"< / code > :< / p >
2022-02-01 06:12:44 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "https://sheetjs.com"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > Tooltip< / span > :< span class = "pl-s" > "Find us @ SheetJS.com!"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Note that Excel does not automatically style hyperlinks -- they will generally
be displayed as normal text.< / p >
2022-02-01 06:12:44 +00:00
< p > < em > Remote Links< / em > < / p >
< p > HTTP / HTTPS links can be used directly:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A2'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "https://docs.sheetjs.com/#hyperlinks"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A3'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "http://localhost:7262/yes_localhost_works"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > Excel also supports < code > mailto< / code > email links with subject line:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A4'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "mailto:ignored@dev.null"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A5'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "mailto:ignored@dev.null?subject=Test Subject"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > < em > Local Links< / em > < / p >
< p > Links to absolute paths should use the < code > file://< / code > URI scheme:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'B1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "file:///SheetJS/t.xlsx"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to /SheetJS/t.xlsx */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'B2'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "file:///c:/SheetJS.xlsx"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to c:\SheetJS.xlsx */< / span > < / pre > < / div >
< p > Links to relative paths can be specified without a scheme:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'B3'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "SheetJS.xlsb"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to SheetJS.xlsb */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'B4'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "../SheetJS.xlsm"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to ../SheetJS.xlsm */< / span > < / pre > < / div >
< p > Relative Paths have undefined behavior in the SpreadsheetML 2003 format. Excel
2019 will treat a < code > ..\< / code > parent mark as two levels up.< / p >
< p > < em > Internal Links< / em > < / p >
2020-01-28 05:02:07 +00:00
< p > Links where the target is a cell or range or defined name in the same workbook
("Internal Links") are marked with a leading hash character:< / p >
2022-02-01 06:12:44 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'C1'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "#E2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to cell E2 */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'C2'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "#Sheet2!E2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to cell E2 in sheet Sheet2 */< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'C3'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > l< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > Target< / span > :< span class = "pl-s" > "#SomeDefinedName"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > /* Link to Defined Name */< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< h4 >
< a id = "user-content-cell-comments" class = "anchor" href = "#cell-comments" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Cell Comments< / h4 >
< p > Cell comments are objects stored in the < code > c< / code > array of cell objects. The actual
contents of the comment are split into blocks based on the comment author. The
< code > a< / code > field of each comment object is the author of the comment and the < code > t< / code > field
is the plain text representation.< / p >
< p > For example, the following snippet appends a cell comment into cell < code > A1< / code > :< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "I'm a little comment, short and stout!"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Note: XLSB enforces a 54 character limit on the Author name. Names longer than
54 characters may cause issues with other formats.< / p >
< p > To mark a comment as normally hidden, set the < code > hidden< / code > property:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "This comment is visible"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > hidden< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "This comment will be hidden"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2022-03-25 04:01:40 +00:00
< p > < em > Threaded Comments< / em > < / p >
< p > Introduced in Excel 365, threaded comments are plain text comment snippets with
author metadata and parent references. They are supported in XLSX and XLSB.< / p >
< p > To mark a comment as threaded, each comment part must have a true < code > T< / code > property:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A1< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "This is not threaded"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > )< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > =< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > hidden< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "This is threaded"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > T< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > A2< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > push< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > a< / span > :< span class = "pl-s" > "JSSheet"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-s" > "This is also threaded"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > T< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< p > There is no Active Directory or Office 365 metadata associated with authors in a thread.< / p >
2020-01-28 05:02:07 +00:00
< h4 >
< a id = "user-content-sheet-visibility" class = "anchor" href = "#sheet-visibility" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Sheet Visibility< / h4 >
< p > Excel enables hiding sheets in the lower tab bar. The sheet data is stored in
the file but the UI does not readily make it available. Standard hidden sheets
are revealed in the "Unhide" menu. Excel also has "very hidden" sheets which
cannot be revealed in the menu. It is only accessible in the VB Editor!< / p >
< p > The visibility setting is stored in the < code > Hidden< / code > property of sheet props array.< / p >
< details >
< summary > < b > More details< / b > (click to show)< / summary >
< table >
< thead >
< tr >
< th align = "center" > Value< / th >
< th align = "left" > Definition< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "center" > 0< / td >
< td align = "left" > Visible< / td >
< / tr >
< tr >
< td align = "center" > 1< / td >
< td align = "left" > Hidden< / td >
< / tr >
< tr >
< td align = "center" > 2< / td >
< td align = "left" > Very Hidden< / td >
< / tr >
< / tbody >
< / table >
2021-08-27 00:16:16 +00:00
< p > With < a href = "https://rawgit.com/SheetJS/test_files/HEAD/sheet_visibility.xlsx" rel = "nofollow" > https://rawgit.com/SheetJS/test_files/HEAD/sheet_visibility.xlsx< / a > :< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-k" > return< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Hidden< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'Visible'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'Hidden'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'VeryHidden'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Non-Excel formats do not support the Very Hidden state. The best way to test
if a sheet is visible is to check if the < code > Hidden< / code > property is logical truth:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Workbook< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-k" > function< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span > < span class = "pl-k" > return< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > name< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > x< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Hidden< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'Visible'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'Hidden'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'VeryHidden'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > false< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h4 >
< a id = "user-content-vba-and-macros" class = "anchor" href = "#vba-and-macros" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > VBA and Macros< / h4 >
< p > VBA Macros are stored in a special data blob that is exposed in the < code > vbaraw< / code >
property of the workbook object when the < code > bookVBA< / code > option is < code > true< / code > . They are
supported in < code > XLSM< / code > , < code > XLSB< / code > , and < code > BIFF8 XLS< / code > formats. The supported format
writers automatically insert the data blobs if it is present in the workbook and
associate with the worksheet names.< / p >
< details >
< summary > < b > Custom Code Names< / b > (click to show)< / summary >
< p > The workbook code name is stored in < code > wb.Workbook.WBProps.CodeName< / code > . By default,
Excel will write < code > ThisWorkbook< / code > or a translated phrase like < code > DieseArbeitsmappe< / code > .
Worksheet and Chartsheet code names are in the worksheet properties object at
< code > wb.Workbook.Sheets[i].CodeName< / code > . Macrosheets and Dialogsheets are ignored.< / p >
< p > The readers and writers preserve the code names, but they have to be manually
set when adding a VBA blob to a different workbook.< / p >
< / details >
< details >
< summary > < b > Macrosheets< / b > (click to show)< / summary >
< p > Older versions of Excel also supported a non-VBA "macrosheet" sheet type that
stored automation commands. These are exposed in objects with the < code > !type< / code >
property set to < code > "macro"< / code > .< / p >
< / details >
< details >
< summary > < b > Detecting macros in workbooks< / b > (click to show)< / summary >
< p > The < code > vbaraw< / code > field will only be set if macros are present, so testing is simple:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > function< / span > < span class = "pl-en" > wb_has_macro< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c" > /*:workbook*/< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c" > /*:boolean*/< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > if< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > !< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > vbaraw< / span > < span class = "pl-kos" > )< / span > < span class = "pl-k" > return< / span > < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > const< / span > < span class = "pl-s1" > sheets< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > SheetNames< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > map< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > n< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-s1" > wb< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > Sheets< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > n< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > return< / span > < span class = "pl-s1" > sheets< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > some< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > )< / span > < span class = "pl-c1" > => < / span > < span class = "pl-c1" > !< / span > < span class = "pl-c1" > !< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > & & < / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > '!type'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > ==< / span > < span class = "pl-s" > 'macro'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > }< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h2 >
< a id = "user-content-parsing-options" class = "anchor" href = "#parsing-options" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Parsing Options< / h2 >
< p > The exported < code > read< / code > and < code > readFile< / code > functions accept an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "right" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > type< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > Input data encoding (see Input Type below)< / td >
< / tr >
< tr >
< td align = "left" > < code > raw< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, plain text parsing will not parse values **< / td >
< / tr >
< tr >
< td align = "left" > < code > codepage< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > If specified, use code page when appropriate **< / td >
< / tr >
< tr >
< td align = "left" > < code > cellFormula< / code > < / td >
< td align = "right" > true< / td >
< td align = "left" > Save formulae to the .f field< / td >
< / tr >
< tr >
< td align = "left" > < code > cellHTML< / code > < / td >
< td align = "right" > true< / td >
< td align = "left" > Parse rich text and save HTML to the < code > .h< / code > field< / td >
< / tr >
< tr >
< td align = "left" > < code > cellNF< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > Save number format string to the < code > .z< / code > field< / td >
< / tr >
< tr >
< td align = "left" > < code > cellStyles< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > Save style/theme info to the < code > .s< / code > field< / td >
< / tr >
< tr >
< td align = "left" > < code > cellText< / code > < / td >
< td align = "right" > true< / td >
< td align = "left" > Generated formatted text to the < code > .w< / code > field< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > If specified, use the string for date code 14 **< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetStubs< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > Create cell objects of type < code > z< / code > for stub cells< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetRows< / code > < / td >
< td align = "right" > 0< / td >
< td align = "left" > If > 0, read the first < code > sheetRows< / code > rows **< / td >
< / tr >
< tr >
< td align = "left" > < code > bookDeps< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, parse calculation chains< / td >
< / tr >
< tr >
< td align = "left" > < code > bookFiles< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, add raw files to book object **< / td >
< / tr >
< tr >
< td align = "left" > < code > bookProps< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, only parse enough to get book metadata **< / td >
< / tr >
< tr >
< td align = "left" > < code > bookSheets< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, only parse enough to get the sheet names< / td >
< / tr >
< tr >
< td align = "left" > < code > bookVBA< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, copy VBA blob to < code > vbaraw< / code > field **< / td >
< / tr >
< tr >
< td align = "left" > < code > password< / code > < / td >
< td align = "right" > ""< / td >
< td align = "left" > If defined and file is encrypted, use password **< / td >
< / tr >
< tr >
< td align = "left" > < code > WTF< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, throw errors on unexpected file features **< / td >
< / tr >
< tr >
< td align = "left" > < code > sheets< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > If specified, only parse specified sheets **< / td >
< / tr >
2021-08-27 00:16:16 +00:00
< tr >
< td align = "left" > < code > PRN< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, allow parsing of PRN files **< / td >
< / tr >
< tr >
< td align = "left" > < code > xlfn< / code > < / td >
< td align = "right" > false< / td >
< td align = "left" > If true, preserve < code > _xlfn.< / code > prefixes in formulae **< / td >
< / tr >
2022-02-01 06:12:44 +00:00
< tr >
< td align = "left" > < code > FS< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > DSV Field Separator override< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
< ul >
< li > Even if < code > cellNF< / code > is false, formatted text will be generated and saved to < code > .w< / code >
< / li >
< li > In some cases, sheets may be parsed even if < code > bookSheets< / code > is false.< / li >
< li > Excel aggressively tries to interpret values from CSV and other plain text.
This leads to surprising behavior! The < code > raw< / code > option suppresses value parsing.< / li >
< li >
< code > bookSheets< / code > and < code > bookProps< / code > combine to give both sets of information< / li >
< li >
< code > Deps< / code > will be an empty object if < code > bookDeps< / code > is false< / li >
< li >
< code > bookFiles< / code > behavior depends on file type:
< ul >
< li >
< code > keys< / code > array (paths in the ZIP) for ZIP-based formats< / li >
< li >
< code > files< / code > hash (mapping paths to objects representing the files) for ZIP< / li >
< li >
< code > cfb< / code > object for formats using CFB containers< / li >
< / ul >
< / li >
< li >
< code > sheetRows-1< / code > rows will be generated when looking at the JSON object output
(since the header row is counted as a row when parsing the data)< / li >
< li > By default all worksheets are parsed. < code > sheets< / code > restricts based on input type:
< ul >
< li > number: zero-based index of worksheet to parse (< code > 0< / code > is first worksheet)< / li >
< li > string: name of worksheet to parse (case insensitive)< / li >
< li > array of numbers and strings to select multiple worksheets.< / li >
< / ul >
< / li >
< li >
< code > bookVBA< / code > merely exposes the raw VBA CFB object. It does not parse the data.
XLSM and XLSB store the VBA CFB object in < code > xl/vbaProject.bin< / code > . BIFF8 XLS mixes
the VBA entries alongside the core Workbook entry, so the library generates a
new XLSB-compatible blob from the XLS CFB container.< / li >
< li >
< code > codepage< / code > is applied to BIFF2 - BIFF5 files without < code > CodePage< / code > records and to
CSV files without BOM in < code > type:"binary"< / code > . BIFF8 XLS always defaults to 1200.< / li >
2021-08-27 00:16:16 +00:00
< li >
< code > PRN< / code > affects parsing of text files without a common delimiter character.< / li >
2020-01-28 05:02:07 +00:00
< li > Currently only XOR encryption is supported. Unsupported error will be thrown
for files employing other encryption methods.< / li >
2021-08-27 00:16:16 +00:00
< li > Newer Excel functions are serialized with the < code > _xlfn.< / code > prefix, hidden from the
user. SheetJS will strip < code > _xlfn.< / code > normally. The < code > xlfn< / code > option preserves them.< / li >
2020-01-28 05:02:07 +00:00
< li > WTF is mainly for development. By default, the parser will suppress read
errors on single worksheets, allowing you to read from the worksheets that do
2021-08-27 00:16:16 +00:00
parse properly. Setting < code > WTF:true< / code > forces those errors to be thrown.< / li >
2020-01-28 05:02:07 +00:00
< / ul >
< h3 >
< a id = "user-content-input-type" class = "anchor" href = "#input-type" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Input Type< / h3 >
< p > Strings can be interpreted in multiple ways. The < code > type< / code > parameter for < code > read< / code >
tells the library how to parse the data argument:< / p >
< table >
< thead >
< tr >
< th > < code > type< / code > < / th >
< th > expected input< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > "base64"< / code > < / td >
< td > string: Base64 encoding of the file< / td >
< / tr >
< tr >
< td > < code > "binary"< / code > < / td >
< td > string: binary string (byte < code > n< / code > is < code > data.charCodeAt(n)< / code > )< / td >
< / tr >
< tr >
< td > < code > "string"< / code > < / td >
< td > string: JS string (characters interpreted as UTF8)< / td >
< / tr >
< tr >
< td > < code > "buffer"< / code > < / td >
< td > nodejs Buffer< / td >
< / tr >
< tr >
< td > < code > "array"< / code > < / td >
< td > array: array of 8-bit unsigned int (byte < code > n< / code > is < code > data[n]< / code > )< / td >
< / tr >
< tr >
< td > < code > "file"< / code > < / td >
< td > string: path of file that will be read (nodejs only)< / td >
< / tr >
< / tbody >
< / table >
< h3 >
< a id = "user-content-guessing-file-type" class = "anchor" href = "#guessing-file-type" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Guessing File Type< / h3 >
< details >
< summary > < b > Implementation Details< / b > (click to show)< / summary >
< p > Excel and other spreadsheet tools read the first few bytes and apply other
heuristics to determine a file type. This enables file type punning: renaming
files with the < code > .xls< / code > extension will tell your computer to use Excel to open the
file but Excel will know how to handle it. This library applies similar logic:< / p >
< table >
< thead >
< tr >
< th align = "left" > Byte 0< / th >
< th align = "left" > Raw File Type< / th >
< th align = "left" > Spreadsheet Types< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > 0xD0< / code > < / td >
< td align = "left" > CFB Container< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > BIFF 5/8 or protected XLSX/XLSB or WQ3/QPW or XLR< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > < code > 0x09< / code > < / td >
< td align = "left" > BIFF Stream< / td >
< td align = "left" > BIFF 2/3/4/5< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x3C< / code > < / td >
< td align = "left" > XML/HTML< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x50< / code > < / td >
< td align = "left" > ZIP Archive< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > XLSB or XLSX/M or ODS or UOS2 or NUMBERS or text< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > < code > 0x49< / code > < / td >
< td align = "left" > Plain Text< / td >
< td align = "left" > SYLK or plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x54< / code > < / td >
< td align = "left" > Plain Text< / td >
< td align = "left" > DIF or plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0xEF< / code > < / td >
< td align = "left" > UTF8 Encoded< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0xFF< / code > < / td >
< td align = "left" > UTF16 Encoded< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x00< / code > < / td >
< td align = "left" > Record Stream< / td >
< td align = "left" > Lotus WK* or Quattro Pro or plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x7B< / code > < / td >
< td align = "left" > Plain text< / td >
< td align = "left" > RTF or plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x0A< / code > < / td >
< td align = "left" > Plain text< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x0D< / code > < / td >
< td align = "left" > Plain text< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< tr >
< td align = "left" > < code > 0x20< / code > < / td >
< td align = "left" > Plain text< / td >
< td align = "left" > SpreadsheetML / Flat ODS / UOS1 / HTML / plain text< / td >
< / tr >
< / tbody >
< / table >
< p > DBF files are detected based on the first byte as well as the third and fourth
bytes (corresponding to month and day of the file date)< / p >
2022-02-01 06:12:44 +00:00
< p > Works for Windows files are detected based on the BOF record with type < code > 0xFF< / code > < / p >
2020-01-28 05:02:07 +00:00
< p > Plain text format guessing follows the priority order:< / p >
< table >
< thead >
< tr >
< th align = "left" > Format< / th >
< th align = "left" > Test< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > XML< / td >
< td align = "left" >
< code > < ?xml< / code > appears in the first 1024 characters< / td >
< / tr >
< tr >
< td align = "left" > HTML< / td >
< td align = "left" > starts with < code > < < / code > and HTML tags appear in the first 1024 characters *< / td >
< / tr >
< tr >
< td align = "left" > XML< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > starts with < code > < < / code > and the first tag is valid< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > RTF< / td >
< td align = "left" > starts with < code > {\rt< / code >
< / td >
< / tr >
< tr >
< td align = "left" > DSV< / td >
< td align = "left" > starts with < code > /sep=.$/< / code > , separator is the specified character< / td >
< / tr >
< tr >
< td align = "left" > DSV< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > more unquoted `< / td >
< / tr >
< tr >
< td align = "left" > DSV< / td >
< td align = "left" > more unquoted < code > ;< / code > chars than < code > \t< / code > or < code > ,< / code > in the first 1024< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > TSV< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > more unquoted < code > \t< / code > chars than < code > ,< / code > chars in the first 1024< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > CSV< / td >
< td align = "left" > one of the first 1024 characters is a comma < code > ","< / code >
< / td >
< / tr >
< tr >
< td align = "left" > ETH< / td >
< td align = "left" > starts with < code > socialcalc:version:< / code >
< / td >
< / tr >
< tr >
< td align = "left" > PRN< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" >
< code > PRN< / code > option is set to true< / td >
< / tr >
< tr >
< td align = "left" > CSV< / td >
< td align = "left" > (fallback)< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< / tbody >
< / table >
< ul >
< li > HTML tags include: < code > html< / code > , < code > table< / code > , < code > head< / code > , < code > meta< / code > , < code > script< / code > , < code > style< / code > , < code > div< / code >
< / li >
< / ul >
< / details >
< details >
< summary > < b > Why are random text files valid?< / b > (click to show)< / summary >
< p > Excel is extremely aggressive in reading files. Adding an XLS extension to any
display text file (where the only characters are ANSI display chars) tricks
Excel into thinking that the file is potentially a CSV or TSV file, even if it
is only one column! This library attempts to replicate that behavior.< / p >
< p > The best approach is to validate the desired worksheet and ensure it has the
expected number of rows or columns. Extracting the range is extremely simple:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > range< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > decode_range< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > worksheet< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > '!ref'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ncols< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > -< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > s< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > c< / span > < span class = "pl-c1" > +< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > nrows< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > r< / span > < span class = "pl-c1" > -< / span > < span class = "pl-s1" > range< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > s< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > r< / span > < span class = "pl-c1" > +< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h2 >
< a id = "user-content-writing-options" class = "anchor" href = "#writing-options" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Writing Options< / h2 >
< p > The exported < code > write< / code > and < code > writeFile< / code > functions accept an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "right" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > type< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > Output data encoding (see Output Type below)< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "right" > < code > false< / code > < / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > bookSST< / code > < / td >
< td align = "right" > < code > false< / code > < / td >
< td align = "left" > Generate Shared String Table **< / td >
< / tr >
< tr >
< td align = "left" > < code > bookType< / code > < / td >
< td align = "right" > < code > "xlsx"< / code > < / td >
< td align = "left" > Type of Workbook (see below for supported formats)< / td >
< / tr >
< tr >
< td align = "left" > < code > sheet< / code > < / td >
< td align = "right" > < code > ""< / code > < / td >
< td align = "left" > Name of Worksheet for single-sheet formats **< / td >
< / tr >
< tr >
< td align = "left" > < code > compression< / code > < / td >
< td align = "right" > < code > false< / code > < / td >
< td align = "left" > Use ZIP compression for ZIP-based formats **< / td >
< / tr >
< tr >
< td align = "left" > < code > Props< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > Override workbook properties when writing **< / td >
< / tr >
< tr >
< td align = "left" > < code > themeXLSX< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > Override theme XML when writing XLSX/XLSB/XLSM **< / td >
< / tr >
< tr >
< td align = "left" > < code > ignoreEC< / code > < / td >
< td align = "right" > < code > true< / code > < / td >
< td align = "left" > Suppress "number as text" errors **< / td >
< / tr >
2022-03-25 04:01:40 +00:00
< tr >
< td align = "left" > < code > numbers< / code > < / td >
< td align = "right" > < / td >
< td align = "left" > Payload for NUMBERS export **< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
< ul >
< li >
< code > bookSST< / code > is slower and more memory intensive, but has better compatibility
with older versions of iOS Numbers< / li >
< li > The raw data is the only thing guaranteed to be saved. Features not described
in this README may not be serialized.< / li >
< li >
< code > cellDates< / code > only applies to XLSX output and is not guaranteed to work with
third-party readers. Excel itself does not usually write cells with type < code > d< / code >
so non-Excel tools may ignore the data or error in the presence of dates.< / li >
< li >
< code > Props< / code > is an object mirroring the workbook < code > Props< / code > field. See the table from
the < a href = "#workbook-file-properties" > Workbook File Properties< / a > section.< / li >
< li > if specified, the string from < code > themeXLSX< / code > will be saved as the primary theme
for XLSX/XLSB/XLSM files (to < code > xl/theme/theme1.xml< / code > in the ZIP)< / li >
< li > Due to a bug in the program, some features like "Text to Columns" will crash
Excel on worksheets where error conditions are ignored. The writer will mark
files to ignore the error by default. Set < code > ignoreEC< / code > to < code > false< / code > to suppress.< / li >
2022-03-25 04:01:40 +00:00
< li > Due to the size of the data, the NUMBERS data is not included by default. The
included < code > xlsx.zahl.js< / code > and < code > xlsx.zahl.mjs< / code > scripts include the data.< / li >
2020-01-28 05:02:07 +00:00
< / ul >
< h3 >
< a id = "user-content-supported-output-formats" class = "anchor" href = "#supported-output-formats" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Supported Output Formats< / h3 >
< p > For broad compatibility with third-party tools, this library supports many
output formats. The specific file type is controlled with < code > bookType< / code > option:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > bookType< / code > < / th >
< th align = "right" > file ext< / th >
< th align = "center" > container< / th >
< th align = "left" > sheets< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > xlsx< / code > < / td >
< td align = "right" > < code > .xlsx< / code > < / td >
< td align = "center" > ZIP< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 2007+ XML Format< / td >
< / tr >
< tr >
< td align = "left" > < code > xlsm< / code > < / td >
< td align = "right" > < code > .xlsm< / code > < / td >
< td align = "center" > ZIP< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 2007+ Macro XML Format< / td >
< / tr >
< tr >
< td align = "left" > < code > xlsb< / code > < / td >
< td align = "right" > < code > .xlsb< / code > < / td >
< td align = "center" > ZIP< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 2007+ Binary Format< / td >
< / tr >
< tr >
< td align = "left" > < code > biff8< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > CFB< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 97-2004 Workbook Format< / td >
< / tr >
< tr >
< td align = "left" > < code > biff5< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > CFB< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 5.0/95 Workbook Format< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > < code > biff4< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Excel 4.0 Worksheet Format< / td >
< / tr >
< tr >
< td align = "left" > < code > biff3< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Excel 3.0 Worksheet Format< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > biff2< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Excel 2.0 Worksheet Format< / td >
< / tr >
< tr >
< td align = "left" > < code > xlml< / code > < / td >
< td align = "right" > < code > .xls< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > multi< / td >
< td align = "left" > Excel 2003-2004 (SpreadsheetML)< / td >
< / tr >
< tr >
2022-03-25 04:01:40 +00:00
< td align = "left" > < code > numbers< / code > < / td >
< td align = "right" > < code > .numbers< / code > < / td >
< td align = "center" > ZIP< / td >
< td align = "left" > single< / td >
< td align = "left" > Numbers 3.0+ Spreadsheet< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > ods< / code > < / td >
< td align = "right" > < code > .ods< / code > < / td >
< td align = "center" > ZIP< / td >
< td align = "left" > multi< / td >
< td align = "left" > OpenDocument Spreadsheet< / td >
< / tr >
< tr >
< td align = "left" > < code > fods< / code > < / td >
< td align = "right" > < code > .fods< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > multi< / td >
< td align = "left" > Flat OpenDocument Spreadsheet< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > < code > wk3< / code > < / td >
< td align = "right" > < code > .wk3< / code > < / td >
< td align = "center" > none< / td >
2022-03-25 04:01:40 +00:00
< td align = "left" > multi< / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > Lotus Workbook (WK3)< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > csv< / code > < / td >
< td align = "right" > < code > .csv< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Comma Separated Values< / td >
< / tr >
< tr >
< td align = "left" > < code > txt< / code > < / td >
< td align = "right" > < code > .txt< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > UTF-16 Unicode Text (TXT)< / td >
< / tr >
< tr >
< td align = "left" > < code > sylk< / code > < / td >
< td align = "right" > < code > .sylk< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Symbolic Link (SYLK)< / td >
< / tr >
< tr >
< td align = "left" > < code > html< / code > < / td >
< td align = "right" > < code > .html< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > HTML Document< / td >
< / tr >
< tr >
< td align = "left" > < code > dif< / code > < / td >
< td align = "right" > < code > .dif< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Data Interchange Format (DIF)< / td >
< / tr >
< tr >
< td align = "left" > < code > dbf< / code > < / td >
< td align = "right" > < code > .dbf< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > dBASE II + VFP Extensions (DBF)< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > < code > wk1< / code > < / td >
< td align = "right" > < code > .wk1< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Lotus Worksheet (WK1)< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > rtf< / code > < / td >
< td align = "right" > < code > .rtf< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Rich Text Format (RTF)< / td >
< / tr >
< tr >
< td align = "left" > < code > prn< / code > < / td >
< td align = "right" > < code > .prn< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Lotus Formatted Text< / td >
< / tr >
< tr >
< td align = "left" > < code > eth< / code > < / td >
< td align = "right" > < code > .eth< / code > < / td >
< td align = "center" > none< / td >
< td align = "left" > single< / td >
< td align = "left" > Ethercalc Record Format (ETH)< / td >
< / tr >
< / tbody >
< / table >
< ul >
< li >
< code > compression< / code > only applies to formats with ZIP containers.< / li >
< li > Formats that only support a single sheet require a < code > sheet< / code > option specifying
the worksheet. If the string is empty, the first worksheet is used.< / li >
< li >
< code > writeFile< / code > will automatically guess the output file format based on the file
extension if < code > bookType< / code > is not specified. It will choose the first format in
the aforementioned table that matches the extension.< / li >
< / ul >
< h3 >
< a id = "user-content-output-type" class = "anchor" href = "#output-type" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Output Type< / h3 >
< p > The < code > type< / code > argument for < code > write< / code > mirrors the < code > type< / code > argument for < code > read< / code > :< / p >
< table >
< thead >
< tr >
< th > < code > type< / code > < / th >
< th > output< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > < code > "base64"< / code > < / td >
< td > string: Base64 encoding of the file< / td >
< / tr >
< tr >
< td > < code > "binary"< / code > < / td >
< td > string: binary string (byte < code > n< / code > is < code > data.charCodeAt(n)< / code > )< / td >
< / tr >
< tr >
< td > < code > "string"< / code > < / td >
< td > string: JS string (characters interpreted as UTF8)< / td >
< / tr >
< tr >
< td > < code > "buffer"< / code > < / td >
< td > nodejs Buffer< / td >
< / tr >
< tr >
< td > < code > "array"< / code > < / td >
< td > ArrayBuffer, fallback array of 8-bit unsigned int< / td >
< / tr >
< tr >
< td > < code > "file"< / code > < / td >
< td > string: path of file that will be created (nodejs only)< / td >
< / tr >
< / tbody >
< / table >
2022-03-25 04:01:40 +00:00
< ul >
< li > For compatibility with Excel, < code > csv< / code > output will always include the UTF-8 byte
order mark.< / li >
< / ul >
2020-01-28 05:02:07 +00:00
< h2 >
< a id = "user-content-utility-functions" class = "anchor" href = "#utility-functions" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Utility Functions< / h2 >
< p > The < code > sheet_to_*< / code > functions accept a worksheet and an optional options object.< / p >
< p > The < code > *_to_sheet< / code > functions accept a data object and an optional options object.< / p >
< p > The examples are based on the following worksheet:< / p >
< pre > < code > XXX| A | B | C | D | E | F | G |
---+---+---+---+---+---+---+---+
1 | S | h | e | e | t | J | S |
2 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
3 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
< / code > < / pre >
< h3 >
< a id = "user-content-array-of-arrays-input" class = "anchor" href = "#array-of-arrays-input" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Array of Arrays Input< / h3 >
< p > < code > XLSX.utils.aoa_to_sheet< / code > takes an array of arrays of JS values and returns a
worksheet resembling the input data. Numbers, Booleans and Strings are stored
as the corresponding styles. Dates are stored as date or numbers. Array holes
and explicit < code > undefined< / code > values are skipped. < code > null< / code > values may be stubbed. All
other values are stored as strings. The function takes an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetStubs< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Create cell objects of type < code > z< / code > for < code > null< / code > values< / td >
< / tr >
2022-02-01 06:12:44 +00:00
< tr >
< td align = "left" > < code > nullError< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, emit < code > #NULL!< / code > error cells for < code > null< / code > values< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > To generate the example sheet:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > split< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > ""< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ]< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< p > < code > XLSX.utils.sheet_add_aoa< / code > takes an array of arrays of JS values and updates an
existing worksheet object. It follows the same process as < code > aoa_to_sheet< / code > and
accepts an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetStubs< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Create cell objects of type < code > z< / code > for < code > null< / code > values< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > < code > nullError< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, emit < code > #NULL!< / code > error cells for < code > null< / code > values< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > origin< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Use specified cell as starting point (see below)< / td >
< / tr >
< / tbody >
< / table >
< p > < code > origin< / code > is expected to be one of:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > origin< / code > < / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > (cell object)< / td >
< td align = "left" > Use specified cell (cell object)< / td >
< / tr >
< tr >
< td align = "left" > (string)< / td >
< td align = "left" > Use specified cell (A1-style cell)< / td >
< / tr >
< tr >
< td align = "left" > (number > = 0)< / td >
< td align = "left" > Start from the first column at specified row (0-indexed)< / td >
< / tr >
< tr >
< td align = "left" > -1< / td >
< td align = "left" > Append to bottom of worksheet starting on first column< / td >
< / tr >
< tr >
< td align = "left" > (default)< / td >
< td align = "left" > Start from cell A1< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > Consider the worksheet:< / p >
< pre > < code > XXX| A | B | C | D | E | F | G |
---+---+---+---+---+---+---+---+
1 | S | h | e | e | t | J | S |
2 | 1 | 2 | | | 5 | 6 | 7 |
3 | 2 | 3 | | | 6 | 7 | 8 |
4 | 3 | 4 | | | 7 | 8 | 9 |
5 | 4 | 5 | 6 | 7 | 8 | 9 | 0 |
< / code > < / pre >
< p > This worksheet can be built up in the order < code > A1:G1, A2:B4, E2:G4, A5:G5< / code > :< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* Initial row */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > aoa_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "SheetJS"< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > split< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > ""< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Write data starting at A2 */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s" > "A2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Write data starting at E2 */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 9< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > :< span class = "pl-kos" > {< / span > < span class = "pl-c1" > r< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > c< / span > :< span class = "pl-c1" > 4< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Append row */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_aoa< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 9< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
< a id = "user-content-array-of-objects-input" class = "anchor" href = "#array-of-objects-input" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Array of Objects Input< / h3 >
< p > < code > XLSX.utils.json_to_sheet< / code > takes an array of objects and returns a worksheet
with automatically-generated "headers" based on the keys of the objects. The
default column order is determined by the first appearance of the field using
2022-02-01 06:12:44 +00:00
< code > Object.keys< / code > . The function accepts an options argument:< / p >
2020-01-28 05:02:07 +00:00
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > header< / code > < / td >
< td align = "center" > < / td >
2022-02-01 06:12:44 +00:00
< td align = "left" > Use specified field order (default < code > Object.keys< / code > ) **< / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > skipHeader< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, do not include header row in output< / td >
< / tr >
2022-02-01 06:12:44 +00:00
< tr >
< td align = "left" > < code > nullError< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, emit < code > #NULL!< / code > error cells for < code > null< / code > values< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
2022-02-01 06:12:44 +00:00
< ul >
< li > All fields from each row will be written. If < code > header< / code > is an array and it does
not contain a particular field, the key will be appended to the array.< / li >
< li > Cell types are deduced from the type of each value. For example, a < code > Date< / code >
object will generate a Date cell, while a string will generate a Text cell.< / li >
< li > Null values will be skipped by default. If < code > nullError< / code > is true, an error cell
corresponding to < code > #NULL!< / code > will be written to the worksheet.< / li >
< / ul >
2020-01-28 05:02:07 +00:00
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > The original sheet cannot be reproduced using plain objects since JS object keys
must be unique. After replacing the second < code > e< / code > and < code > S< / code > with < code > e_1< / code > and < code > S_1< / code > :< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > S< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > h< / span > :< span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e< / span > :< span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e_1< / span > :< span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > J< / span > :< span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > S_1< / span > :< span class = "pl-c1" > 7< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > S< / span > :< span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > h< / span > :< span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e< / span > :< span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e_1< / span > :< span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > :< span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > J< / span > :< span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > S_1< / span > :< span class = "pl-c1" > 8< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-kos" > [< / span > < span class = "pl-s" > "S"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "h"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "e_1"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "t"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "J"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "S_1"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Alternatively, the header row can be skipped:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > :< span class = "pl-s" > "S"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > :< span class = "pl-s" > "h"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > :< span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > :< span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > :< span class = "pl-s" > "t"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > :< span class = "pl-s" > "J"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > :< span class = "pl-s" > "S"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-kos" > [< / span > < span class = "pl-s" > "A"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "D"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "E"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "F"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "G"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > skipHeader< / span > :< span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< p > < code > XLSX.utils.sheet_add_json< / code > takes an array of objects and updates an existing
worksheet object. It follows the same process as < code > json_to_sheet< / code > and accepts
an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > header< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Use specified column order (default < code > Object.keys< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > skipHeader< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, do not include header row in output< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > < code > nullError< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, emit < code > #NULL!< / code > error cells for < code > null< / code > values< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > < code > origin< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Use specified cell as starting point (see below)< / td >
< / tr >
< / tbody >
< / table >
< p > < code > origin< / code > is expected to be one of:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > origin< / code > < / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > (cell object)< / td >
< td align = "left" > Use specified cell (cell object)< / td >
< / tr >
< tr >
< td align = "left" > (string)< / td >
< td align = "left" > Use specified cell (A1-style cell)< / td >
< / tr >
< tr >
< td align = "left" > (number > = 0)< / td >
< td align = "left" > Start from the first column at specified row (0-indexed)< / td >
< / tr >
< tr >
< td align = "left" > -1< / td >
< td align = "left" > Append to bottom of worksheet starting on first column< / td >
< / tr >
< tr >
< td align = "left" > (default)< / td >
< td align = "left" > Start from cell A1< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > Consider the worksheet:< / p >
< pre > < code > XXX| A | B | C | D | E | F | G |
---+---+---+---+---+---+---+---+
1 | S | h | e | e | t | J | S |
2 | 1 | 2 | | | 5 | 6 | 7 |
3 | 2 | 3 | | | 6 | 7 | 8 |
4 | 3 | 4 | | | 7 | 8 | 9 |
5 | 4 | 5 | 6 | 7 | 8 | 9 | 0 |
< / code > < / pre >
< p > This worksheet can be built up in the order < code > A1:G1, A2:B4, E2:G4, A5:G5< / code > :< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c" > /* Initial row */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > json_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > "S"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-s" > "h"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-s" > "e"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > "t"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-s" > "J"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-s" > "S"< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-kos" > [< / span > < span class = "pl-s" > "A"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "D"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "E"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "F"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "G"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > skipHeader< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Write data starting at A2 */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > skipHeader< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-s" > "A2"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Write data starting at E2 */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 9< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > skipHeader< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-kos" > {< / span > < span class = "pl-c1" > r< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > c< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-kos" > [< / span > < span class = "pl-s" > "A"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c" > /* Append row */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > [< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-c1" > 9< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > }< / span >
< span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > : < span class = "pl-kos" > [< / span > < span class = "pl-s" > "A"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "B"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "C"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "D"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "E"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "F"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "G"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > skipHeader< / span > : < span class = "pl-c1" > true< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
< a id = "user-content-html-table-input" class = "anchor" href = "#html-table-input" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > HTML Table Input< / h3 >
< p > < code > XLSX.utils.table_to_sheet< / code > takes a table DOM element and returns a worksheet
resembling the input table. Numbers are parsed. All other data will be stored
as strings.< / p >
< p > < code > XLSX.utils.table_to_book< / code > produces a minimal workbook based on the worksheet.< / p >
< p > Both functions accept options arguments:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > raw< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > If true, every cell will hold raw strings< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetRows< / code > < / td >
< td align = "center" > 0< / td >
< td align = "left" > If > 0, read the first < code > sheetRows< / code > rows of the table< / td >
< / tr >
< tr >
< td align = "left" > < code > display< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, hidden rows and cells will not be parsed< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > To generate the example sheet, start with the HTML table:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-text-html-basic" > < pre > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > table< / span > < span class = "pl-c1" > id< / span > ="< span class = "pl-s" > sheetjs< / span > "< span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > S< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > h< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > e< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > e< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > t< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > J< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > S< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 1< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 2< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 3< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 4< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 5< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 6< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 7< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < < / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 2< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 3< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 4< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 5< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 6< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 7< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < < / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > 8< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > td< / span > < span class = "pl-kos" > > < / span > < span class = "pl-kos" > < /< / span > < span class = "pl-ent" > tr< / span > < span class = "pl-kos" > > < / span >
< span class = "pl-kos" > < /< / span > < span class = "pl-ent" > table< / span > < span class = "pl-kos" > > < / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > To process the table:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > var< / span > < span class = "pl-s1" > tbl< / span > < span class = "pl-c1" > =< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'sheetjs'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > wb< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_book< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > tbl< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< p > Note: < code > XLSX.read< / code > can handle HTML represented as strings.< / p >
2021-08-27 00:16:16 +00:00
< p > < code > XLSX.utils.sheet_add_dom< / code > takes a table DOM element and updates an existing
worksheet object. It follows the same process as < code > table_to_sheet< / code > and accepts
an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > raw< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > If true, every cell will hold raw strings< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > cellDates< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Store dates as type < code > d< / code > (default is < code > n< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > sheetRows< / code > < / td >
< td align = "center" > 0< / td >
< td align = "left" > If > 0, read the first < code > sheetRows< / code > rows of the table< / td >
< / tr >
< tr >
< td align = "left" > < code > display< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, hidden rows and cells will not be parsed< / td >
< / tr >
< / tbody >
< / table >
< p > < code > origin< / code > is expected to be one of:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > origin< / code > < / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > (cell object)< / td >
< td align = "left" > Use specified cell (cell object)< / td >
< / tr >
< tr >
< td align = "left" > (string)< / td >
< td align = "left" > Use specified cell (A1-style cell)< / td >
< / tr >
< tr >
< td align = "left" > (number > = 0)< / td >
< td align = "left" > Start from the first column at specified row (0-indexed)< / td >
< / tr >
< tr >
< td align = "left" > -1< / td >
< td align = "left" > Append to bottom of worksheet starting on first column< / td >
< / tr >
< tr >
< td align = "left" > (default)< / td >
< td align = "left" > Start from cell A1< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > A small helper function can create gap rows between tables:< / p >
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-k" > function< / span > < span class = "pl-en" > create_gap_rows< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > nrows< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > {< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ref< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > decode_range< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!ref"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // get original range< / span >
< span class = "pl-s1" > ref< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > e< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > r< / span > < span class = "pl-c1" > +=< / span > < span class = "pl-s1" > nrows< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // add to ending row< / span >
< span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > "!ref"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > encode_range< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ref< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // reassign row< / span >
< span class = "pl-kos" > }< / span >
< span class = "pl-c" > /* first table */< / span >
< span class = "pl-k" > var< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > table_to_sheet< / span > < span class = "pl-kos" > (< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'table1'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-en" > create_gap_rows< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // one row gap after first table< / span >
< span class = "pl-c" > /* second table */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_dom< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'table2'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-en" > create_gap_rows< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // three rows gap after second table< / span >
< span class = "pl-c" > /* third table */< / span >
< span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_add_dom< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-smi" > document< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > getElementById< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s" > 'table3'< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > origin< / span > : < span class = "pl-c1" > -< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span > < / pre > < / div >
< / details >
2020-01-28 05:02:07 +00:00
< h3 >
< a id = "user-content-formulae-output" class = "anchor" href = "#formulae-output" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Formulae Output< / h3 >
< p > < code > XLSX.utils.sheet_to_formulae< / code > generates an array of commands that represent
how a person would enter data into an application. Each entry is of the form
< code > A1-cell-address=formula-or-value< / code > . String literals are prefixed with a < code > '< / code > in
accordance with Excel.< / p >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > For the example sheet:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-k" > var< / span > < span class = "pl-s1" > o< / span > < span class = "pl-c1" > =< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_formulae< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c1" > > < / span > < span class = "pl-kos" > [< / span > < span class = "pl-s1" > o< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 0< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > o< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > o< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 10< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > o< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 15< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > o< / span > < span class = "pl-kos" > [< / span > < span class = "pl-c1" > 20< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A1=\'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'F1=\'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'D2=4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'B3=3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'G3=8'< / span > < span class = "pl-kos" > ]< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
< a id = "user-content-delimiter-separated-output" class = "anchor" href = "#delimiter-separated-output" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Delimiter-Separated Output< / h3 >
< p > As an alternative to the < code > writeFile< / code > CSV type, < code > XLSX.utils.sheet_to_csv< / code > also
produces CSV output. The function takes an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > FS< / code > < / td >
< td align = "center" > < code > ","< / code > < / td >
< td align = "left" > "Field Separator" delimiter between fields< / td >
< / tr >
< tr >
< td align = "left" > < code > RS< / code > < / td >
< td align = "center" > < code > "\n"< / code > < / td >
< td align = "left" > "Record Separator" delimiter between rows< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > strip< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Remove trailing field separators in each record **< / td >
< / tr >
< tr >
< td align = "left" > < code > blankrows< / code > < / td >
< td align = "center" > true< / td >
< td align = "left" > Include blank lines in the CSV output< / td >
< / tr >
< tr >
< td align = "left" > < code > skipHidden< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Skips hidden rows/columns in the CSV output< / td >
< / tr >
2021-08-27 00:16:16 +00:00
< tr >
< td align = "left" > < code > forceQuotes< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > Force quotes around fields< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
< ul >
< li >
< code > strip< / code > will remove trailing commas from each line under default < code > FS/RS< / code >
< / li >
< li >
< code > blankrows< / code > must be set to < code > false< / code > to skip blank lines.< / li >
2021-08-27 00:16:16 +00:00
< li > Fields containing the record or field separator will automatically be wrapped
in double quotes; < code > forceQuotes< / code > forces all cells to be wrapped in quotes.< / li >
2022-03-25 04:01:40 +00:00
< li >
< code > XLSX.write< / code > with < code > csv< / code > type will always prepend the UTF-8 byte-order mark for
Excel compatibility. < code > sheet_to_csv< / code > returns a JS string and omits the mark.
Using < code > XLSX.write< / code > with type < code > string< / code > will also skip the mark.< / li >
2020-01-28 05:02:07 +00:00
< / ul >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > For the example sheet:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-smi" > console< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > log< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_csv< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-v" > S< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > h< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > e< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s1" > t< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-v" > J< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-v" > S< / span >
< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span >
< span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span >
< span class = "pl-c1" > > < / span > < span class = "pl-smi" > console< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > log< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_csv< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > FS< / span > :< span class = "pl-s" > "\t"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-v" > S< / span > < span class = "pl-s1" > h< / span > < span class = "pl-s1" > e< / span > < span class = "pl-s1" > e< / span > < span class = "pl-s1" > t< / span > < span class = "pl-v" > J< / span > < span class = "pl-v" > S< / span >
2020-01-28 05:02:07 +00:00
< span class = "pl-c1" > 1< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-c1" > 7< / span >
< span class = "pl-c1" > 2< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-c1" > 8< / span >
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-smi" > console< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > log< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_csv< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > FS< / span > :< span class = "pl-s" > ":"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > RS< / span > :< span class = "pl-s" > "|"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-v" > S< / span > :< span class = "pl-s1" > h< / span > :< span class = "pl-s1" > e< / span > :< span class = "pl-s1" > e< / span > :< span class = "pl-s1" > t< / span > :< span class = "pl-v" > J< / span > :< span class = "pl-v" > S< / span > < span class = "pl-c1" > |< / span > < span class = "pl-c1" > 1< / span > :< span class = "pl-c1" > 2< / span > :< span class = "pl-c1" > 3< / span > :< span class = "pl-c1" > 4< / span > :< span class = "pl-c1" > 5< / span > :< span class = "pl-c1" > 6< / span > :< span class = "pl-c1" > 7< / span > < span class = "pl-c1" > |< / span > < span class = "pl-c1" > 2< / span > :< span class = "pl-c1" > 3< / span > :< span class = "pl-c1" > 4< / span > :< span class = "pl-c1" > 5< / span > :< span class = "pl-c1" > 6< / span > :< span class = "pl-c1" > 7< / span > :< span class = "pl-c1" > 8< / span > < span class = "pl-c1" > |< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h4 >
< a id = "user-content-utf-16-unicode-text" class = "anchor" href = "#utf-16-unicode-text" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > UTF-16 Unicode Text< / h4 >
< p > The < code > txt< / code > output type uses the tab character as the field separator. If the
< code > codepage< / code > library is available (included in full distribution but not core),
the output will be encoded in < code > CP1200< / code > and the BOM will be prepended.< / p >
< p > < code > XLSX.utils.sheet_to_txt< / code > takes the same arguments as < code > sheet_to_csv< / code > .< / p >
< h3 >
< a id = "user-content-html-output" class = "anchor" href = "#html-output" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > HTML Output< / h3 >
< p > As an alternative to the < code > writeFile< / code > HTML type, < code > XLSX.utils.sheet_to_html< / code > also
produces HTML output. The function takes an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > id< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Specify the < code > id< / code > attribute for the < code > TABLE< / code > element< / td >
< / tr >
< tr >
< td align = "left" > < code > editable< / code > < / td >
< td align = "center" > false< / td >
< td align = "left" > If true, set < code > contenteditable="true"< / code > for every TD< / td >
< / tr >
< tr >
< td align = "left" > < code > header< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Override header (default < code > html body< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > footer< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Override footer (default < code > /body /html< / code > )< / td >
< / tr >
< / tbody >
< / table >
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > For the example sheet:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-smi" > console< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > log< / span > < span class = "pl-kos" > (< / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_html< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-c" > // ...< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h3 >
< a id = "user-content-json" class = "anchor" href = "#json" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > JSON< / h3 >
< p > < code > XLSX.utils.sheet_to_json< / code > generates different types of JS objects. The function
takes an options argument:< / p >
< table >
< thead >
< tr >
< th align = "left" > Option Name< / th >
< th align = "center" > Default< / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > raw< / code > < / td >
< td align = "center" > < code > true< / code > < / td >
< td align = "left" > Use raw values (true) or formatted strings (false)< / td >
< / tr >
< tr >
< td align = "left" > < code > range< / code > < / td >
< td align = "center" > from WS< / td >
< td align = "left" > Override Range (see table below)< / td >
< / tr >
< tr >
< td align = "left" > < code > header< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Control output format (see table below)< / td >
< / tr >
< tr >
< td align = "left" > < code > dateNF< / code > < / td >
< td align = "center" > FMT 14< / td >
< td align = "left" > Use specified date format in string output< / td >
< / tr >
< tr >
< td align = "left" > < code > defval< / code > < / td >
< td align = "center" > < / td >
< td align = "left" > Use specified value in place of null or undefined< / td >
< / tr >
< tr >
< td align = "left" > < code > blankrows< / code > < / td >
< td align = "center" > **< / td >
< td align = "left" > Include blank lines in the output **< / td >
< / tr >
< / tbody >
< / table >
< ul >
< li >
< code > raw< / code > only affects cells which have a format code (< code > .z< / code > ) field or a formatted
text (< code > .w< / code > ) field.< / li >
< li > If < code > header< / code > is specified, the first row is considered a data row; if < code > header< / code >
is not specified, the first row is the header row and not considered data.< / li >
< li > When < code > header< / code > is not specified, the conversion will automatically disambiguate
header entries by affixing < code > _< / code > and a count starting at < code > 1< / code > . For example, if
three columns have header < code > foo< / code > the output fields are < code > foo< / code > , < code > foo_1< / code > , < code > foo_2< / code >
< / li >
< li >
< code > null< / code > values are returned when < code > raw< / code > is true but are skipped when false.< / li >
< li > If < code > defval< / code > is not specified, null and undefined values are skipped normally.
If specified, all null and undefined points will be filled with < code > defval< / code >
< / li >
< li > When < code > header< / code > is < code > 1< / code > , the default is to generate blank rows. < code > blankrows< / code > must
be set to < code > false< / code > to skip blank rows.< / li >
< li > When < code > header< / code > is not < code > 1< / code > , the default is to skip blank rows. < code > blankrows< / code > must
be true to generate blank rows< / li >
< / ul >
< p > < code > range< / code > is expected to be one of:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > range< / code > < / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > (number)< / td >
< td align = "left" > Use worksheet range but set starting row to the value< / td >
< / tr >
< tr >
< td align = "left" > (string)< / td >
< td align = "left" > Use specified range (A1-style bounded range string)< / td >
< / tr >
< tr >
< td align = "left" > (default)< / td >
< td align = "left" > Use worksheet range (< code > ws['!ref']< / code > )< / td >
< / tr >
< / tbody >
< / table >
< p > < code > header< / code > is expected to be one of:< / p >
< table >
< thead >
< tr >
< th align = "left" > < code > header< / code > < / th >
< th align = "left" > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > 1< / code > < / td >
< td align = "left" > Generate an array of arrays ("2D Array")< / td >
< / tr >
< tr >
< td align = "left" > < code > "A"< / code > < / td >
< td align = "left" > Row object keys are literal column labels< / td >
< / tr >
< tr >
< td align = "left" > array of strings< / td >
< td align = "left" > Use specified strings as keys in row objects< / td >
< / tr >
< tr >
< td align = "left" > (default)< / td >
< td align = "left" > Read and disambiguate first row as keys< / td >
< / tr >
< / tbody >
< / table >
2022-03-25 04:01:40 +00:00
< ul >
< li > If header is not < code > 1< / code > , the row object will contain the non-enumerable property
< code > __rowNum__< / code > that represents the row of the sheet corresponding to the entry.< / li >
< li > If header is an array, the keys will not be disambiguated. This can lead to
unexpected results if the array values are not unique!< / li >
< / ul >
2020-01-28 05:02:07 +00:00
< details >
< summary > < b > Examples< / b > (click to show)< / summary >
< p > For the example sheet:< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > S< / span > : < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > h< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e_1< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > J< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > S_1< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > S< / span > : < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > h< / span > : < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e< / span > : < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > e_1< / span > : < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > t< / span > : < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > J< / span > : < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > S_1< / span > : < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-s" > "A"< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-s" > 'h'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > 't'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-s" > 'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > '1'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > B< / span > : < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > C< / span > : < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > D< / span > : < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > F< / span > : < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > G< / span > : < span class = "pl-s" > '8'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-kos" > [< / span > < span class = "pl-s" > "A"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "E"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "I"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "O"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "U"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "6"< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > "9"< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > {< / span > < span class = "pl-s" > '6'< / span > : < span class = "pl-s" > 'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '9'< / span > : < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > 'h'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > I< / span > : < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > O< / span > : < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > U< / span > : < span class = "pl-s" > 't'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-s" > '6'< / span > : < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '9'< / span > : < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > '1'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > I< / span > : < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > O< / span > : < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > U< / span > : < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > {< / span > < span class = "pl-s" > '6'< / span > : < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '9'< / span > : < span class = "pl-s" > '8'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > A< / span > : < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > E< / span > : < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > I< / span > : < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > O< / span > : < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > U< / span > : < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > ]< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'h'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 't'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > '1'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '8'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< p > Example showing the effect of < code > raw< / code > :< / p >
2021-08-27 00:16:16 +00:00
< div class = "highlight highlight-source-js" > < pre > < span class = "pl-c1" > > < / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'A2'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > w< / span > < span class = "pl-c1" > =< / span > < span class = "pl-s" > "3"< / span > < span class = "pl-kos" > ;< / span > < span class = "pl-c" > // set A2 formatted string value< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > raw< / span > :< span class = "pl-c1" > false< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'h'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 't'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- A2 uses the formatted string< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-s" > '2'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '3'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '4'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '5'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '6'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '7'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > '8'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span >
2020-01-28 05:02:07 +00:00
2021-08-27 00:16:16 +00:00
< span class = "pl-c1" > > < / span > < span class = "pl-c1" > XLSX< / span > < span class = "pl-kos" > .< / span > < span class = "pl-c1" > utils< / span > < span class = "pl-kos" > .< / span > < span class = "pl-en" > sheet_to_json< / span > < span class = "pl-kos" > (< / span > < span class = "pl-s1" > ws< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-kos" > {< / span > < span class = "pl-c1" > header< / span > :< span class = "pl-c1" > 1< / span > < span class = "pl-kos" > }< / span > < span class = "pl-kos" > )< / span > < span class = "pl-kos" > ;< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-kos" > [< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'h'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'e'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 't'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'J'< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-s" > 'S'< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 1< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c" > // < -- A2 uses the raw value< / span >
< span class = "pl-kos" > [< / span > < span class = "pl-c1" > 2< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 3< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 4< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 5< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 6< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 7< / span > < span class = "pl-kos" > ,< / span > < span class = "pl-c1" > 8< / span > < span class = "pl-kos" > ]< / span > < span class = "pl-kos" > ]< / span > < / pre > < / div >
2020-01-28 05:02:07 +00:00
< / details >
< h2 >
< a id = "user-content-file-formats" class = "anchor" href = "#file-formats" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > File Formats< / h2 >
< p > Despite the library name < code > xlsx< / code > , it supports numerous spreadsheet file formats:< / p >
< table >
< thead >
< tr >
< th align = "left" > Format< / th >
< th align = "center" > Read< / th >
< th align = "center" > Write< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < strong > Excel Worksheet/Workbook Formats< / strong > < / td >
< td align = "center" > :-----:< / td >
< td align = "center" > :-----:< / td >
< / tr >
< tr >
< td align = "left" > Excel 2007+ XML Formats (XLSX/XLSM)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 2007+ Binary Format (XLSB BIFF12)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 2003-2004 XML Format (XML "SpreadsheetML")< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 97-2004 (XLS BIFF8)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 5.0/95 (XLS BIFF5)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 4.0 (XLS/XLW BIFF4)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Excel 3.0 (XLS BIFF3)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
2022-05-11 21:03:03 +00:00
< td align = "left" > Excel 2.0/2.1 / Multiplan 4.x DOS (XLS BIFF2)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > < strong > Excel Supported Text Formats< / strong > < / td >
< td align = "center" > :-----:< / td >
< td align = "center" > :-----:< / td >
< / tr >
< tr >
< td align = "left" > Delimiter-Separated Values (CSV/TXT)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Data Interchange Format (DIF)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Symbolic Link (SYLK/SLK)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Lotus Formatted Text (PRN)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > UTF-16 Unicode Text (TXT)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > < strong > Other Workbook/Worksheet Formats< / strong > < / td >
< td align = "center" > :-----:< / td >
< td align = "center" > :-----:< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2022-03-25 04:01:40 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2022-02-01 06:12:44 +00:00
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > OpenDocument Spreadsheet (ODS)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Flat XML ODF Spreadsheet (FODS)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Uniform Office Format Spreadsheet (标文通 UOS1/UOS2)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > dBASE II/III/IV / Visual FoxPro (DBF)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > Lotus 1-2-3 (WK1/WK3)< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< / tr >
< tr >
< td align = "left" > Lotus 1-2-3 (WKS/WK2/WK4/123)< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > Quattro Pro Spreadsheet (WQ1/WQ2/WB1/WB2/WB3/QPW)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > Works 1.x-3.x DOS / 2.x-5.x Windows Spreadsheet (WKS)< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > Works 6.x-9.x Spreadsheet (XLR)< / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< td align = "center" > < / td >
< / tr >
< tr >
< td align = "left" > < strong > Other Common Spreadsheet Output Formats< / strong > < / td >
< td align = "center" > :-----:< / td >
< td align = "center" > :-----:< / td >
< / tr >
< tr >
< td align = "left" > HTML Tables< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Rich Text Format tables (RTF)< / td >
< td align = "center" > < / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< tr >
< td align = "left" > Ethercalc Record Format (ETH)< / td >
2022-02-01 06:12:44 +00:00
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
< td align = "center" > < g-emoji class = "g-emoji" alias = "heavy_check_mark" fallback-src = "https://github.githubassets.com/images/icons/emoji/unicode/2714.png" > ✔< / g-emoji > < / td >
2020-01-28 05:02:07 +00:00
< / tr >
< / tbody >
< / table >
< p > Features not supported by a given file format will not be written. Formats with
range limits will be silently truncated:< / p >
< table >
< thead >
< tr >
< th align = "left" > Format< / th >
< th align = "left" > Last Cell< / th >
< th align = "right" > Max Cols< / th >
< th align = "right" > Max Rows< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > Excel 2007+ XML Formats (XLSX/XLSM)< / td >
< td align = "left" > XFD1048576< / td >
< td align = "right" > 16384< / td >
< td align = "right" > 1048576< / td >
< / tr >
< tr >
< td align = "left" > Excel 2007+ Binary Format (XLSB BIFF12)< / td >
< td align = "left" > XFD1048576< / td >
< td align = "right" > 16384< / td >
< td align = "right" > 1048576< / td >
< / tr >
< tr >
2022-04-14 17:50:18 +00:00
< td align = "left" > Numbers 12.0 (NUMBERS)< / td >
< td align = "left" > ALL1000000< / td >
< td align = "right" > 1000< / td >
< td align = "right" > 1000000< / td >
< / tr >
< tr >
2022-05-11 21:03:03 +00:00
< td align = "left" > Quattro Pro 9+ (QPW)< / td >
< td align = "left" > IV1000000< / td >
< td align = "right" > 256< / td >
< td align = "right" > 1000000< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > Excel 97-2004 (XLS BIFF8)< / td >
< td align = "left" > IV65536< / td >
< td align = "right" > 256< / td >
< td align = "right" > 65536< / td >
< / tr >
< tr >
< td align = "left" > Excel 5.0/95 (XLS BIFF5)< / td >
< td align = "left" > IV16384< / td >
< td align = "right" > 256< / td >
< td align = "right" > 16384< / td >
< / tr >
< tr >
2022-02-01 06:12:44 +00:00
< td align = "left" > Excel 4.0 (XLS BIFF4)< / td >
< td align = "left" > IV16384< / td >
< td align = "right" > 256< / td >
< td align = "right" > 16384< / td >
< / tr >
< tr >
< td align = "left" > Excel 3.0 (XLS BIFF3)< / td >
< td align = "left" > IV16384< / td >
< td align = "right" > 256< / td >
< td align = "right" > 16384< / td >
< / tr >
< tr >
2020-01-28 05:02:07 +00:00
< td align = "left" > Excel 2.0/2.1 (XLS BIFF2)< / td >
< td align = "left" > IV16384< / td >
< td align = "right" > 256< / td >
< td align = "right" > 16384< / td >
< / tr >
2022-02-01 06:12:44 +00:00
< tr >
< td align = "left" > Lotus 1-2-3 R2 - R5 (WK1/WK3/WK4)< / td >
< td align = "left" > IV8192< / td >
< td align = "right" > 256< / td >
< td align = "right" > 8192< / td >
< / tr >
< tr >
< td align = "left" > Lotus 1-2-3 R1 (WKS)< / td >
< td align = "left" > IV2048< / td >
< td align = "right" > 256< / td >
< td align = "right" > 2048< / td >
< / tr >
2020-01-28 05:02:07 +00:00
< / tbody >
< / table >
< p > Excel 2003 SpreadsheetML range limits are governed by the version of Excel and
are not enforced by the writer.< / p >
< details >
2022-02-14 02:02:46 +00:00
< summary > < b > File Format Details< / b > (click to show)< / summary >
< p > < strong > Core Spreadsheet Formats< / strong > < / p >
< ul >
< li > < strong > Excel 2007+ XML (XLSX/XLSM)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > XLSX and XLSM files are ZIP containers containing a series of XML files in
accordance with the Open Packaging Conventions (OPC). The XLSM format, almost
identical to XLSX, is used for files containing macros.< / p >
< p > The format is standardized in ECMA-376 and later in ISO/IEC 29500. Excel does
not follow the specification, and there are additional documents discussing how
Excel deviates from the specification.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Excel 2.0-95 (BIFF2/BIFF3/BIFF4/BIFF5)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > BIFF 2/3 XLS are single-sheet streams of binary records. Excel 4 introduced
the concept of a workbook (< code > XLW< / code > files) but also had single-sheet < code > XLS< / code > format.
The structure is largely similar to the Lotus 1-2-3 file formats. BIFF5/8/12
extended the format in various ways but largely stuck to the same record format.< / p >
2022-05-11 21:03:03 +00:00
< p > Multiplan 4 "Normal" files are identical in structure to BIFF2 and use the same
cell value records. There are some different record types for more advanced
features like Print Settings. The BIFF2 writer generates files that can be read
in Multiplan 4 and the parser can extract values from "Normal" files.< / p >
2020-01-28 05:02:07 +00:00
< p > There is no official specification for any of these formats. Excel 95 can write
files in these formats, so record lengths and fields were determined by writing
in all of the supported formats and comparing files. Excel 2016 can generate
BIFF5 files, enabling a full suite of file tests starting from XLSX or BIFF2.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Excel 97-2004 Binary (BIFF8)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > BIFF8 exclusively uses the Compound File Binary container format, splitting some
content into streams within the file. At its core, it still uses an extended
version of the binary record format from older versions of BIFF.< / p >
< p > The < code > MS-XLS< / code > specification covers the basics of the file format, and other
specifications expand on serialization of features like properties.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Excel 2003-2004 (SpreadsheetML)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > Predating XLSX, SpreadsheetML files are simple XML files. There is no official
and comprehensive specification, although MS has released documentation on the
format. Since Excel 2016 can generate SpreadsheetML files, mapping features is
pretty straightforward.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Excel 2007+ Binary (XLSB, BIFF12)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > Introduced in parallel with XLSX, the XLSB format combines the BIFF architecture
with the content separation and ZIP container of XLSX. For the most part nodes
in an XLSX sub-file can be mapped to XLSB records in a corresponding sub-file.< / p >
< p > The < code > MS-XLSB< / code > specification covers the basics of the file format, and other
specifications expand on serialization of features like properties.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Delimiter-Separated Values (CSV/TXT)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > Excel CSV deviates from RFC4180 in a number of important ways. The generated
CSV files should generally work in Excel although they may not work in RFC4180
compatible readers. The parser should generally understand Excel CSV. The
writer proactively generates cells for formulae if values are unavailable.< / p >
< p > Excel TXT uses tab as the delimiter and code page 1200.< / p >
2022-02-14 02:02:46 +00:00
< p > Like in Excel, files starting with < code > 0x49 0x44 ("ID")< / code > are treated as Symbolic
2020-01-28 05:02:07 +00:00
Link files. Unlike Excel, if the file does not have a valid SYLK header, it
will be proactively reinterpreted as CSV. There are some files with semicolon
delimiter that align with a valid SYLK file. For the broadest compatibility,
2022-02-14 02:02:46 +00:00
all cells with the value of < code > ID< / code > are automatically wrapped in double-quotes.< / p >
< p > < strong > Miscellaneous Workbook Formats< / strong > < / p >
< p > Support for other formats is generally far behind XLS/XLSB/XLSX support, due in
2020-01-28 05:02:07 +00:00
part to a lack of publicly available documentation. Test files were produced in
the respective apps and compared to their XLS exports to determine structure.
The main focus is data extraction.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Lotus 1-2-3 (WKS/WK1/WK2/WK3/WK4/123)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > The Lotus formats consist of binary records similar to the BIFF structure. Lotus
did release a specification decades ago covering the original WK1 format. Other
features were deduced by producing files and comparing to Excel support.< / p >
2022-02-01 06:12:44 +00:00
< p > Generated WK1 worksheets are compatible with Lotus 1-2-3 R2 and Excel 5.0.< / p >
< p > Generated WK3 workbooks are compatible with Lotus 1-2-3 R9 and Excel 5.0.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Quattro Pro (WQ1/WQ2/WB1/WB2/WB3/QPW)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > The Quattro Pro formats use binary records in the same way as BIFF and Lotus.
Some of the newer formats (namely WB3 and QPW) use a CFB enclosure just like
BIFF8 XLS.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Works for DOS / Windows Spreadsheet (WKS/XLR)< / strong > < / li >
< / ul >
2022-02-01 06:12:44 +00:00
< p > All versions of Works were limited to a single worksheet.< / p >
< p > Works for DOS 1.x - 3.x and Works for Windows 2.x extends the Lotus WKS format
with additional record types.< / p >
< p > Works for Windows 3.x - 5.x uses the same format and WKS extension. The BOF
record has type < code > FF< / code > < / p >
< p > Works for Windows 6.x - 9.x use the XLR format. XLR is nearly identical to
BIFF8 XLS: it uses the CFB container with a Workbook stream. Works 9 saves the
exact Workbook stream for the XLR and the 97-2003 XLS export. Works 6 XLS
includes two empty worksheets but the main worksheet has an identical encoding.
XLR also includes a < code > WksSSWorkBook< / code > stream similar to Lotus FM3/FMT files.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Numbers 3.0+ / iWork 2013+ Spreadsheet (NUMBERS)< / strong > < / li >
< / ul >
2022-02-01 06:12:44 +00:00
< p > iWork 2013 (Numbers 3.0 / Pages 5.0 / Keynote 6.0) switched from a proprietary
XML-based format to the current file format based on the iWork Archive (IWA).
This format has been used up through the current release (Numbers 11.2).< / p >
< p > The parser focuses on extracting raw data from tables. Numbers technically
supports multiple tables in a logical worksheet, including custom titles. This
parser will generate one worksheet per Numbers table.< / p >
2022-03-25 04:01:40 +00:00
< p > The writer currently exports a small range from the first worksheet.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > OpenDocument Spreadsheet (ODS/FODS)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > ODS is an XML-in-ZIP format akin to XLSX while FODS is an XML format akin to
SpreadsheetML. Both are detailed in the OASIS standard, but tools like LO/OO
add undocumented extensions. The parsers and writers do not implement the full
standard, instead focusing on parts necessary to extract and store raw data.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Uniform Office Spreadsheet (UOS1/2)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > UOS is a very similar format, and it comes in 2 varieties corresponding to ODS
and FODS respectively. For the most part, the difference between the formats
is in the names of tags and attributes.< / p >
2022-02-14 02:02:46 +00:00
< p > < strong > Miscellaneous Worksheet Formats< / strong > < / p >
2020-01-28 05:02:07 +00:00
< p > Many older formats supported only one worksheet:< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > dBASE and Visual FoxPro (DBF)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > DBF is really a typed table format: each column can only hold one data type and
each record omits type information. The parser generates a header row and
inserts records starting at the second row of the worksheet. The writer makes
files compatible with Visual FoxPro extensions.< / p >
< p > Multi-file extensions like external memos and tables are currently unsupported,
limited by the general ability to read arbitrary files in the web browser. The
reader understands DBF Level 7 extensions like DATETIME.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Symbolic Link (SYLK)< / strong > < / li >
< / ul >
2022-05-11 21:03:03 +00:00
< p > < a href = "https://oss.sheetjs.com/notes/sylk/" rel = "nofollow" > https://oss.sheetjs.com/notes/sylk/< / a > is an informal specification based on our
experimentation and previous documentation efforts.< / p >
2020-01-28 05:02:07 +00:00
< ul >
2022-05-11 21:03:03 +00:00
< li > < strong > Lotus Formatted Text (PRN)< / strong > < / li >
2020-01-28 05:02:07 +00:00
< / ul >
< p > There is no real documentation, and in fact Excel treats PRN as an output-only
file format. Nevertheless we can guess the column widths and reverse-engineer
the original layout. Excel's 240 character width limitation is not enforced.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Data Interchange Format (DIF)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > There is no unified definition. Visicalc DIF differs from Lotus DIF, and both
differ from Excel DIF. Where ambiguous, the parser/writer follows the expected
behavior from Excel. In particular, Excel extends DIF in incompatible ways:< / p >
< ul >
2022-02-14 02:02:46 +00:00
< li >
< p > Since Excel automatically converts numbers-as-strings to numbers, numeric
string constants are converted to formulae: < code > "0.3" -> "=""0.3""< / code > < / p >
< / li >
< li >
< p > DIF technically expects numeric cells to hold the raw numeric data, but Excel
permits formatted numbers (including dates)< / p >
< / li >
< li >
< p > DIF technically has no support for formulae, but Excel will automatically
convert plain formulae. Array formulae are not preserved.< / p >
< / li >
< li >
< p > < strong > HTML< / strong > < / p >
2020-01-28 05:02:07 +00:00
< / li >
< / ul >
< p > Excel HTML worksheets include special metadata encoded in styles. For example,
< code > mso-number-format< / code > is a localized string containing the number format. Despite
the metadata the output is valid HTML, although it does accept bare < code > & < / code > symbols.< / p >
< p > The writer adds type metadata to the TD elements via the < code > t< / code > tag. The parser
looks for those tags and overrides the default interpretation. For example, text
like < code > < td> 12345< /td> < / code > will be parsed as numbers but < code > < td t="s"> 12345< /td> < / code > will
be parsed as text.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Rich Text Format (RTF)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > Excel RTF worksheets are stored in clipboard when copying cells or ranges from a
worksheet. The supported codes are a subset of the Word RTF support.< / p >
2022-02-14 02:02:46 +00:00
< ul >
< li > < strong > Ethercalc Record Format (ETH)< / strong > < / li >
< / ul >
2020-01-28 05:02:07 +00:00
< p > < a href = "https://ethercalc.net/" rel = "nofollow" > Ethercalc< / a > is an open source web spreadsheet powered by
a record format reminiscent of SYLK wrapped in a MIME multi-part message.< / p >
< / details >
< h2 >
< a id = "user-content-testing" class = "anchor" href = "#testing" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Testing< / h2 >
< h3 >
< a id = "user-content-node" class = "anchor" href = "#node" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Node< / h3 >
< details >
< summary > (click to show)< / summary >
< p > < code > make test< / code > will run the node-based tests. By default it runs tests on files in
every supported format. To test a specific file type, set < code > FMTS< / code > to the format
you want to test. Feature-specific tests are available with < code > make test_misc< / code > < / p >
< div class = "highlight highlight-source-shell" > < pre > $ make test_misc < span class = "pl-c" > < span class = "pl-c" > #< / span > run core tests< / span >
$ make < span class = "pl-c1" > test< / span > < span class = "pl-c" > < span class = "pl-c" > #< / span > run full tests< / span >
$ make test_xls < span class = "pl-c" > < span class = "pl-c" > #< / span > only use the XLS test files< / span >
$ make test_xlsx < span class = "pl-c" > < span class = "pl-c" > #< / span > only use the XLSX test files< / span >
$ make test_xlsb < span class = "pl-c" > < span class = "pl-c" > #< / span > only use the XLSB test files< / span >
$ make test_xml < span class = "pl-c" > < span class = "pl-c" > #< / span > only use the XML test files< / span >
$ make test_ods < span class = "pl-c" > < span class = "pl-c" > #< / span > only use the ODS test files< / span > < / pre > < / div >
< p > To enable all errors, set the environment variable < code > WTF=1< / code > :< / p >
< div class = "highlight highlight-source-shell" > < pre > $ make < span class = "pl-c1" > test< / span > < span class = "pl-c" > < span class = "pl-c" > #< / span > run full tests< / span >
$ WTF=1 make < span class = "pl-c1" > test< / span > < span class = "pl-c" > < span class = "pl-c" > #< / span > enable all error messages< / span > < / pre > < / div >
< p > < code > flow< / code > and < code > eslint< / code > checks are available:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ make lint < span class = "pl-c" > < span class = "pl-c" > #< / span > eslint checks< / span >
$ make flow < span class = "pl-c" > < span class = "pl-c" > #< / span > make lint + Flow checking< / span >
$ make tslint < span class = "pl-c" > < span class = "pl-c" > #< / span > check TS definitions< / span > < / pre > < / div >
< / details >
< h3 >
< a id = "user-content-browser" class = "anchor" href = "#browser" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Browser< / h3 >
< details >
< summary > (click to show)< / summary >
< p > The core in-browser tests are available at < code > tests/index.html< / code > within this repo.
Start a local server and navigate to that directory to run the tests.
< code > make ctestserv< / code > will start a server on port 8000.< / p >
< p > < code > make ctest< / code > will generate the browser fixtures. To add more files, edit the
< code > tests/fixtures.lst< / code > file and add the paths.< / p >
< p > To run the full in-browser tests, clone the repo for
< a href = "https://github.com/SheetJS/SheetJS.github.io" > < code > oss.sheetjs.com< / code > < / a > and replace
the < code > xlsx.js< / code > file (then open a browser window and go to < code > stress.html< / code > ):< / p >
< div class = "highlight highlight-source-shell" > < pre > $ cp xlsx.js ../SheetJS.github.io
$ < span class = "pl-c1" > cd< / span > ../SheetJS.github.io
$ simplehttpserver < span class = "pl-c" > < span class = "pl-c" > #< / span > or "python -mSimpleHTTPServer" or "serve"< / span >
$ open -a Chromium.app http://localhost:8000/stress.html< / pre > < / div >
< / details >
< h3 >
< a id = "user-content-tested-environments" class = "anchor" href = "#tested-environments" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Tested Environments< / h3 >
< details >
< summary > (click to show)< / summary >
< ul >
< li > NodeJS < code > 0.8< / code > , < code > 0.10< / code > , < code > 0.12< / code > , < code > 4.x< / code > , < code > 5.x< / code > , < code > 6.x< / code > , < code > 7.x< / code > , < code > 8.x< / code >
< / li >
< li > IE 6/7/8/9/10/11 (IE 6-9 require shims)< / li >
< li > Chrome 24+ (including Android 4.0+)< / li >
< li > Safari 6+ (iOS and Desktop)< / li >
< li > Edge 13+, FF 18+, and Opera 12+< / li >
< / ul >
2021-08-27 00:16:16 +00:00
< p > Tests utilize the mocha testing framework.< / p >
2020-01-28 05:02:07 +00:00
< ul >
< li >
< a href = "https://saucelabs.com/u/sheetjs" rel = "nofollow" > https://saucelabs.com/u/sheetjs< / a > for XLS* modules using Sauce Labs< / li >
< / ul >
2021-08-27 00:16:16 +00:00
< p > The test suite also includes tests for various time zones. To change
2020-01-28 05:02:07 +00:00
the timezone locally, set the TZ environment variable:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ env TZ=< span class = "pl-s" > < span class = "pl-pds" > "< / span > Asia/Kolkata< span class = "pl-pds" > "< / span > < / span > WTF=1 make test_misc< / pre > < / div >
< / details >
< h3 >
< a id = "user-content-test-files" class = "anchor" href = "#test-files" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Test Files< / h3 >
< p > Test files are housed in < a href = "https://github.com/SheetJS/test_files" > another repo< / a > .< / p >
< p > Running < code > make init< / code > will refresh the < code > test_files< / code > submodule and get the files.
Note that this requires < code > svn< / code > , < code > git< / code > , < code > hg< / code > and other commands that may not be
available. If < code > make init< / code > fails, please download the latest version of the test
files snapshot from < a href = "https://github.com/SheetJS/test_files/releases" > the repo< / a > < / p >
< details >
< summary > < b > Latest Snapshot< / b > (click to show)< / summary >
< p > Latest test files snapshot:
< a href = "http://github.com/SheetJS/test_files/releases/download/20170409/test_files.zip" > http://github.com/SheetJS/test_files/releases/download/20170409/test_files.zip< / a > < / p >
< p > (download and unzip to the < code > test_files< / code > subdirectory)< / p >
< / details >
< h2 >
< a id = "user-content-contributing" class = "anchor" href = "#contributing" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Contributing< / h2 >
< p > Due to the precarious nature of the Open Specifications Promise, it is very
important to ensure code is cleanroom. < a href = "CONTRIBUTING.md" > Contribution Notes< / a > < / p >
< details >
< summary > < b > File organization< / b > (click to show)< / summary >
< p > At a high level, the final script is a concatenation of the individual files in
the < code > bits< / code > folder. Running < code > make< / code > should reproduce the final output on all
platforms. The README is similarly split into bits in the < code > docbits< / code > folder.< / p >
< p > Folders:< / p >
< table >
< thead >
< tr >
< th align = "left" > folder< / th >
< th align = "left" > contents< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td align = "left" > < code > bits< / code > < / td >
< td align = "left" > raw source files that make up the final script< / td >
< / tr >
< tr >
< td align = "left" > < code > docbits< / code > < / td >
< td align = "left" > raw markdown files that make up < code > README.md< / code >
< / td >
< / tr >
< tr >
< td align = "left" > < code > bin< / code > < / td >
< td align = "left" > server-side bin scripts (< code > xlsx.njs< / code > )< / td >
< / tr >
< tr >
< td align = "left" > < code > dist< / code > < / td >
< td align = "left" > dist files for web browsers and nonstandard JS environments< / td >
< / tr >
< tr >
< td align = "left" > < code > demos< / code > < / td >
< td align = "left" > demo projects for platforms like ExtendScript and Webpack< / td >
< / tr >
< tr >
< td align = "left" > < code > tests< / code > < / td >
< td align = "left" > browser tests (run < code > make ctest< / code > to rebuild)< / td >
< / tr >
< tr >
< td align = "left" > < code > types< / code > < / td >
< td align = "left" > typescript definitions and tests< / td >
< / tr >
< tr >
< td align = "left" > < code > misc< / code > < / td >
< td align = "left" > miscellaneous supporting scripts< / td >
< / tr >
< tr >
< td align = "left" > < code > test_files< / code > < / td >
< td align = "left" > test files (pulled from the test files repository)< / td >
< / tr >
< / tbody >
< / table >
< / details >
< p > After cloning the repo, running < code > make help< / code > will display a list of commands.< / p >
< h3 >
< a id = "user-content-osxlinux" class = "anchor" href = "#osxlinux" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > OSX/Linux< / h3 >
< details >
< summary > (click to show)< / summary >
< p > The < code > xlsx.js< / code > file is constructed from the files in the < code > bits< / code > subdirectory. The
build script (run < code > make< / code > ) will concatenate the individual bits to produce the
script. Before submitting a contribution, ensure that running make will produce
the < code > xlsx.js< / code > file exactly. The simplest way to test is to add the script:< / p >
< div class = "highlight highlight-source-shell" > < pre > $ git add xlsx.js
$ make clean
$ make
$ git diff xlsx.js< / pre > < / div >
< p > To produce the dist files, run < code > make dist< / code > . The dist files are updated in each
version release and < em > should not be committed between versions< / em > .< / p >
< / details >
< h3 >
< a id = "user-content-windows" class = "anchor" href = "#windows" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Windows< / h3 >
< details >
< summary > (click to show)< / summary >
< p > The included < code > make.cmd< / code > script will build < code > xlsx.js< / code > from the < code > bits< / code > directory.
Building is as simple as:< / p >
< div class = "highlight highlight-source-batchfile" > < pre > < span class = "pl-k" > > < / span > make< / pre > < / div >
< p > To prepare development environment:< / p >
< div class = "highlight highlight-source-batchfile" > < pre > < span class = "pl-k" > > < / span > make init< / pre > < / div >
< p > The full list of commands available in Windows are displayed in < code > make help< / code > :< / p >
< pre > < code > make init -- install deps and global modules
make lint -- run eslint linter
make test -- run mocha test suite
make misc -- run smaller test suite
make book -- rebuild README and summary
make help -- display this message
< / code > < / pre >
< p > As explained in < a href = "#test-files" > Test Files< / a > , on Windows the release ZIP file must
be downloaded and extracted. If Bash on Windows is available, it is possible
to run the OSX/Linux workflow. The following steps prepares the environment:< / p >
< div class = "highlight highlight-source-shell" > < pre > < span class = "pl-c" > < span class = "pl-c" > #< / span > Install support programs for the build and test commands< / span >
sudo apt-get install make git subversion mercurial
< span class = "pl-c" > < span class = "pl-c" > #< / span > Install nodejs and NPM within the WSL< / span >
wget -qO- https://deb.nodesource.com/setup_8.x < span class = "pl-k" > |< / span > sudo bash
sudo apt-get install nodejs
< span class = "pl-c" > < span class = "pl-c" > #< / span > Install dev dependencies< / span >
sudo npm install -g mocha voc blanket xlsjs< / pre > < / div >
< / details >
< h3 >
< a id = "user-content-tests" class = "anchor" href = "#tests" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > Tests< / h3 >
< details >
< summary > (click to show)< / summary >
< p > The < code > test_misc< / code > target (< code > make test_misc< / code > on Linux/OSX / < code > make misc< / code > on Windows)
runs the targeted feature tests. It should take 5-10 seconds to perform feature
tests without testing against the entire test battery. New features should be
accompanied with tests for the relevant file formats and features.< / p >
< p > For tests involving the read side, an appropriate feature test would involve
reading an existing file and checking the resulting workbook object. If a
parameter is involved, files should be read with different values to verify that
the feature is working as expected.< / p >
< p > For tests involving a new write feature which can already be parsed, appropriate
feature tests would involve writing a workbook with the feature and then opening
and verifying that the feature is preserved.< / p >
< p > For tests involving a new write feature without an existing read ability, please
add a feature test to the kitchen sink < code > tests/write.js< / code > .< / p >
< / details >
< h2 >
< a id = "user-content-license" class = "anchor" href = "#license" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > License< / h2 >
< p > Please consult the attached LICENSE file for details. All rights not explicitly
granted by the Apache 2.0 License are reserved by the Original Author.< / p >
< h2 >
< a id = "user-content-references" class = "anchor" href = "#references" aria-hidden = "true" > < span aria-hidden = "true" class = "octicon octicon-link" > < / span > < / a > References< / h2 >
< details >
< summary > < b > OSP-covered Specifications< / b > (click to show)< / summary >
< ul >
< li >
< code > MS-CFB< / code > : Compound File Binary File Format< / li >
< li >
< code > MS-CTXLS< / code > : Excel Custom Toolbar Binary File Format< / li >
< li >
< code > MS-EXSPXML3< / code > : Excel Calculation Version 2 Web Service XML Schema< / li >
< li >
< code > MS-ODATA< / code > : Open Data Protocol (OData)< / li >
< li >
< code > MS-ODRAW< / code > : Office Drawing Binary File Format< / li >
< li >
< code > MS-ODRAWXML< / code > : Office Drawing Extensions to Office Open XML Structure< / li >
< li >
< code > MS-OE376< / code > : Office Implementation Information for ECMA-376 Standards Support< / li >
< li >
< code > MS-OFFCRYPTO< / code > : Office Document Cryptography Structure< / li >
< li >
< code > MS-OI29500< / code > : Office Implementation Information for ISO/IEC 29500 Standards Support< / li >
< li >
< code > MS-OLEDS< / code > : Object Linking and Embedding (OLE) Data Structures< / li >
< li >
< code > MS-OLEPS< / code > : Object Linking and Embedding (OLE) Property Set Data Structures< / li >
< li >
< code > MS-OODF3< / code > : Office Implementation Information for ODF 1.2 Standards Support< / li >
< li >
< code > MS-OSHARED< / code > : Office Common Data Types and Objects Structures< / li >
< li >
< code > MS-OVBA< / code > : Office VBA File Format Structure< / li >
< li >
< code > MS-XLDM< / code > : Spreadsheet Data Model File Format< / li >
< li >
< code > MS-XLS< / code > : Excel Binary File Format (.xls) Structure Specification< / li >
< li >
< code > MS-XLSB< / code > : Excel (.xlsb) Binary File Format< / li >
< li >
< code > MS-XLSX< / code > : Excel (.xlsx) Extensions to the Office Open XML SpreadsheetML File Format< / li >
< li >
< code > XLS< / code > : Microsoft Office Excel 97-2007 Binary File Format Specification< / li >
< li >
< code > RTF< / code > : Rich Text Format< / li >
< / ul >
< / details >
< ul >
< li > ISO/IEC 29500:2012(E) "Information technology — Document description and processing languages — Office Open XML File Formats"< / li >
< li > Open Document Format for Office Applications Version 1.2 (29 September 2011)< / li >
< li > Worksheet File Format (From Lotus) December 1984< / li >
< / ul >
2022-03-25 04:01:40 +00:00
< / article >
2020-01-28 05:02:07 +00:00
< / div >
< / div >
< / div >
< / div >
2022-03-25 04:01:40 +00:00
2020-01-28 05:02:07 +00:00
< / div >
2022-03-25 04:01:40 +00:00
< div > < / div >
2020-01-28 05:02:07 +00:00
< / div > < script >
function showCanonicalImages() {
var images = document.getElementsByTagName('img');
if (!images) {
return;
}
for (var index = 0; index < images.length ; index + + ) {
var image = images[index];
if (image.getAttribute('data-canonical-src') & & image.src !== image.getAttribute('data-canonical-src')) {
image.src = image.getAttribute('data-canonical-src');
}
}
}
function scrollToHash() {
if (location.hash & & !document.querySelector(':target')) {
var element = document.getElementById('user-content-' + location.hash.slice(1));
if (element) {
element.scrollIntoView();
}
}
}
function autorefreshContent(eventSourceUrl) {
var initialTitle = document.title;
var contentElement = document.getElementById('grip-content');
var source = new EventSource(eventSourceUrl);
var isRendering = false;
source.onmessage = function(ev) {
var msg = JSON.parse(ev.data);
if (msg.updating) {
isRendering = true;
document.title = '(Rendering) ' + document.title;
} else {
isRendering = false;
document.title = initialTitle;
contentElement.innerHTML = msg.content;
showCanonicalImages();
}
}
source.onerror = function(e) {
if (e.readyState === EventSource.CLOSED & & isRendering) {
isRendering = false;
document.title = initialTitle;
}
}
}
window.onhashchange = function() {
scrollToHash();
}
window.onload = function() {
scrollToHash();
}
showCanonicalImages();
var autorefreshUrl = document.getElementById('preview-page').getAttribute('data-autorefresh-url');
if (autorefreshUrl) {
autorefreshContent(autorefreshUrl);
}
< / script >
< / body >
< / html >