SheetJS works with traditional and modern software for new spreadsheets

SheetJS works with traditional and modern software for new spreadsheets

2022-10-10 0 1,262
Resource Number 44946 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

The SheetJS recommended in this issue is a new spreadsheet for both traditional and modern software.

SheetJS works with traditional and modern software for new spreadsheets插图

File format support

SheetJS Community Edition provides a tried-and-true open source solution for extracting useful data from almost any complex spreadsheet and generating new spreadsheets that work with both traditional and modern software.

SheetJS Pro offers solutions that go beyond data processing: easy editing of complex templates; Use shape to release your inner Picasso; Create custom worksheets using images/charts/pivottables; Evaluate formula expressions and port calculations to Web applications; Automate common spreadsheet tasks and more.

class=”pgc-h-arrow-right” data-track=”4″>

SheetJS works with traditional and modern software for new spreadsheets插图1

class=”pgc-h-arrow-right” data-track=”37″>

Complete browser independent build save dist/xlsx.full.min.js and can be added directly to with < script> Page with tag:

< script lang="javascript"  src="dist/xlsx.full.min.js"> < /script> 

Each individual release script is available at https://cdn.sheetjs.com/. The latest version uses the latest tag:

< ! -- use the latest version --> 
< script lang="javascript"  src="https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js"> < /script> 

can refer to a specific distribution by version:

< ! -- use version 0.18.5 --> 
< script lang="javascript"  src= < / span > "https://cdn.sheetjs.com/xlsx-0.18.5/package/dist/xlsx.full.min.js" & gt; < /script> 

For production use, download the script and add it to the public folder along with other scripts.

Browser build

The full single-file version is generated at dist/xlsx.full.min.js

dist/xlsx.core.min.js omit code page library (XLS encoding not supported)

in dist/xlsx.mini.min.js. Compared to the full version:

    • Skip code page library (XLS encoding not supported)

XLSB/XLS/Lotus 1-2-3 / SpreadsheetML 2003 / Numbers

  • Node flow utility removed

 

These scripts are also available on the CDN:

< ! -- use xlsx.mini.min.js from the latest version --> 
< script lang="javascript"  src="https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.mini.min.js"> < /script> 

ECMAScript module

ECMAScript module builds are saved to xlsx.mjs and can be added directly to pages with script tags, using type=”module” :

< script type="module"> 
import { read,  writeFileXLSX } from "https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs";

/* load the codepage support library for extended support with older formats  */
import { set_cptable } from "https://cdn.sheetjs.com/xlsx-latest/package/xlsx.mjs";
import * as cptable from 'https://cdn.sheetjs.com/xlsx-latest/package/dist/cpexcel.full.mjs';
set_cptable(cptable);
< /script> 

The NodeJS package also exposes modules with the module parameter, which Angular and other projects support:

import { read,  writeFileXLSX } from "xlsx";

/* load the codepage support library for extended support with older formats  */
import { set_cptable } from "xlsx";
import * as cptable from 'xlsx/dist/cpexcel.full.mjs';
set_cptable(cptable); 

class=”pgc-h-arrow-right” data-track=”30″>

Most scenarios involving spreadsheets and data can be divided into 5 parts:

  • Get data : Data can be stored anywhere: local or remote files, databases, HTML tables, or even generated programmatically in a Web browser.
  • Extract data : For spreadsheet files, this involves parsing raw bytes to read cell data. For general JS data, this involves reshaping the data.
  • Processing data : This step from generating summary statistics to cleaning data records is at the heart of the problem.
  • packet : This might involve making a new spreadsheet or using XML to serialize Jsor.stringify or writing XML or simply flattening the data for UI tools.
  • Publish data : The spreadsheet file can be uploaded to the server or written locally. The data can be presented to the user in an HTML TABLE or data grid.

A common problem involves generating a valid spreadsheet export from data stored in an HTML table. In this example, the HTML TABLE on the page will be scraped, a line with the report date will be added at the bottom, and the new file will be generated and downloaded locally. XLSX.writeFile is responsible for packing the data and trying to download it locally:

// Acquire Data (reference to the HTML  table)
var table_elt = document.getElementById("my-table-id");

// Extract Data (create a workbook object from the table)
var workbook = XLSX.utils.table_to_book(table_elt);

// Process Data (add a new row)
var ws = workbook.Sheets["Sheet1"];
XLSX.utils.sheet_add_aoa(ws,  [["Created "+new Date().toISOString()]],  {origin:-1});

// Package and Release Data (`writeFile` tries to write and save an XLSB file)
XLSX.writeFile(workbook, "Report.xlsb"); 

read The library tries to simplify steps 2 and 4 by using the ability to extract useful data from the spreadsheet file (/) and generate a new spreadsheet file from the data (/)readFile. Other utility features, such as use with other common data sources such as HTML tables.
writewriteFiletable_to_book This document and various demonstration projects cover many of the common scenarios and approaches for steps 1 and 5.

class=”pgc-h-arrow-right” data-track=”40″>

Parse workbook

Extract data from spreadsheet bytes

var workbook = XLSX.read(data, opts); 

This method can extract data from a spreadsheet byte stored in a JS string, a “binary string”, a NodeJS buffer, or a typed array (or) read. Uint8ArrayArrayBuffer

Read spreadsheet bytes from local file and extract data

var workbook = XLSX.readFile(filename, opts); 

The readFile method attempts to read the spreadsheet file in the provided path. Browsers are generally not allowed to read files this way (it is considered a security risk), and attempts to read files this way will throw an error.

class=”pgc-h-arrow-right” data-track=”69″> example

Local file in NodeJS server

readFilefs.readFileSync is used under the hood:

var XLSX = require("xlsx");

var workbook = XLSX.readFile("test.xlsx"); 

readFile does not enable helpers for the node ESM. Instead, fs.readFileSync should be used to read file data to Buffer for use with XLSX.read:

import { readFileSync } from "fs";
import { read } from "xlsx/xlsx.mjs";

const buf = readFileSync("test.xlsx");
/* buf is a Buffer */
const workbook = read(buf); 

user-submitted file in the web page

// XLSX is a global from the standalone script

async function handleDropAsync(e) {
  e.stopPropagation(); e.preventDefault();
  const f = e.dataTransfer.files[0];
  /* f is a File */
  const data = await f.arrayBuffer();
  /* data is an ArrayBuffer */
  const workbook = XLSX.read(data);

  /* DO SOMETHING WITH workbook HERE */
}
drop_dom_element.addEventListener("drop", handleDropAsync, false);

For maximum compatibility, FileReader should use API:

function handleDrop(e) {
  e.stopPropagation(); e.preventDefault();
  var f = e.dataTransfer.files[0];
  /* f is a File */
  var reader = new FileReader();
  reader.onload = function(e) {
    var data = e.target.result;
    /* reader.readAsArrayBuffer(file) -> data will be an ArrayBuffer */
    var workbook = XLSX.read(data);

    /* DO SOMETHING WITH workbook HERE */
  };
  reader.readAsArrayBuffer(f);
}
drop_dom_element.addEventListener("drop", handleDrop, false);

Simple Download Example

/**
 * JSON Conversion Excel
 */
function jsonToSheet () {
    let json = [
        {
            "Name of person": "EJ",
            "Gender": "male",
        },
        {
            "Name of person": "LSQ",
            "Gender": "famale",
        }
    ]

    // Instantiate a workbook
    let book = XLSX.utils.book_new()

    // Instantiate a Sheet
    let sheet = XLSX.utils.json_to_sheet(json, {
        header: ['Name of person', 'Gender']
    })

    // Writes the Sheet to the workbook
    XLSX.utils.book_append_sheet(book, sheet, 'Sheet1')

    // Write to the file, directly trigger the browser download
    XLSX.writeFile(book, 'jsonToSheet.xlsx')
}

/**
* Array conversion Excel
 */
function arrayToSheet () {
    let data = [
        ['Name of person', 'Gender'],
        ['EJ', 'male'],
        ['LSQ', 'famale']
    ]

    // Instantiate a workbook
    let book = XLSX.utils.book_new()

    // Instantiate a Sheet
    let sheet = XLSX.utils.aoa_to_sheet(data)

    //Writes the Sheet to the workbook
    XLSX.utils.book_append_sheet(book, sheet, 'Sheet1')

    // Write to the file, directly trigger the browser download
    XLSX.writeFile(book, 'arrayToSheet.xlsx')
}

—END—

Open source protocol:Apache-2.0 License

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code SheetJS works with traditional and modern software for new spreadsheets https://ictcoder.com/kyym/sheetjs-works-with-traditional-and-modern-software-for-new-spreadsheets.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service