当前位置: 首页 > news >正文

国内最好的网站建设公司百度100%秒收录

国内最好的网站建设公司,百度100%秒收录,大连做网站需要多少钱,人力资源做网站的好处简言 SheetJS是一款非常好用的前端处理表格文件的工具。它分社区版和专业版,我们今天来介绍如何简单使用它的社区版。 SheetJS社区版官网 介绍 你应该打开官网浏览具体使用详情。 安装 打开官网在如上图的Installation板块中可以找到各种运行模块的使用方式。 …

简言

SheetJS是一款非常好用的前端处理表格文件的工具。它分社区版和专业版,我们今天来介绍如何简单使用它的社区版。
SheetJS社区版官网

介绍

你应该打开官网浏览具体使用详情。

安装

在这里插入图片描述

打开官网在如上图的Installation板块中可以找到各种运行模块的使用方式。
在这里插入图片描述

一般项目都是webpack或vite这种模块管理打包工具维护的,所以我们看上图的模块。
以npm为例

npm i --save https://cdn.sheetjs.com/xlsx-0.19.2/xlsx-0.19.2.tgz

成功后如下图:
在这里插入图片描述

使用

安装完成后,库可以以xlsx的名称导入:

import { read, writeFileXLSX } from "xlsx";

如果需要XLS支持,则必须手动导入cpexcel.full.mjs:

/* 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);

导入excel

以vue为例,详细文档如下图,如果你使用了以vue为基础的其他方向的框架,例如(Nuxt)可以参考相应的使用文档。
vuejs使用sheetjs
SheetJs有两种解析excel数据的方法,read(data,options)和readFile(filename,options)。

// 直接解析数据
XLSX.read(data, read_opts)
//	根据文件名解析数据
XLSX.readFile(filename, read_opts)

常用的就是XLSX.read(data, read_opts)方法,它可以直接解析存储在JS字符串、“二进制字符串”、Node.js缓冲区或类型化数组(Uint8Array或ArrayBuffer)中的数据。

  1. 获取数据,将数据转成可被read()方法读取的类型
  2. 读取数据,数据将以对象的形式输出。
  3. 最后可以使用官方已实现的工具函数或者自定义处理函数

下面是示例:

<template><div><inputid="inputFile"type="file"accept=".xlsx,.xls,.csv"@change="change"/></div>
</template><script>
import * as XLSX from 'xlsx'
export default {props: {//  表格数据sheetsContent: {type: Object,default: () => {return {}}}},emits: ['success', 'update:sheetsContent'],data() {return {context: ''}},methods: {change(e) {const file = e.target.files[0]const reader = new FileReader()reader.readAsBinaryString(file)reader.onload = re => {const data = re.target.resultthis.$emit('sucess', data)const zzexcel = XLSX.read(data, {type: 'binary'})console.log(zzexcel)this.$emit('update:sheetsContent', zzexcel)//	将表中的数据以json格式输出//	常见的有 sheet_to_html 、sheet_to_csv等const content = XLSX.utils.sheet_to_json(zzexcel.Sheets.Sheet1)console.log(content)this.context = content}}}
}
</script><style></style>

导出excel

导出excel需要有源数据对象,然后才可以导出excel文件。
导出方法有以下三种:

  • XLSX.write(workbook,opts): 从数据生成电子表格字节(文件)。write方法尝试将数据打包到内存中的文件中。默认情况下,会生成XLSX文件,但这可以通过opts参数的bookType属性进行控制。根据type选项,数据可以存储为“二进制字符串”、JS字符串、Uint8Array或缓冲区。
  • XLSX.writeFile(workbook,filename,opts):生成并尝试保存文件。导出文件格式由filename的扩展名决定(SheetJS.xlsx信号XLSX导出、SheetJS.xlsb信号XLSB导出等)。
  • XLSX.writeFileXLSX(workbook,filename,opts): 生成并尝试保存XLSX文件。

示例:

<template><div><table class="table-box"><thead><tr><th>表头1</th><th>表头2</th></tr></thead><tbody><tr><td>1</td><td style="background:#000;color:#fff">2</td></tr></tbody></table><button @click="exportFile">导出</button></div>
</template><script>
import * as XLSX from 'xlsx'
export default {props: {//  表格数据sheetsContent: {type: Object,default: () => {return {}}}},emits: ['success', 'update:sheetsContent'],data() {return {context: ''}},methods: {exportFile() {const tableDom = document.querySelector('.table-box')const workbook = XLSX.utils.table_to_book(tableDom)console.log(workbook)//  文件名带后缀XLSX.writeFileXLSX(workbook, '表1.xlsx')}}
}
</script><style></style>

代码

<template><div><inputid="inputFile"type="file"accept=".xlsx,.xls,.csv"@change="change"/><table class="table-box"><thead><tr><th>表头1</th><th>表头2</th></tr></thead><tbody><tr><td>1</td><td style="background:#000;color:#fff">2</td></tr></tbody></table><button @click="exportFile">导出</button></div>
</template><script>
import * as XLSX from 'xlsx'
export default {props: {//  表格数据sheetsContent: {type: Object,default: () => {return {}}}},emits: ['success', 'update:sheetsContent'],data() {return {context: ''}},methods: {change(e) {const file = e.target.files[0]const reader = new FileReader()reader.readAsBinaryString(file)reader.onload = re => {const data = re.target.resultthis.$emit('sucess', data)const zzexcel = XLSX.read(data, {type: 'binary'})console.log(zzexcel)this.$emit('update:sheetsContent', zzexcel)const content = XLSX.utils.sheet_to_json(zzexcel.Sheets.Sheet1)console.log(content)this.context = content}},exportFile() {const tableDom = document.querySelector('.table-box')const workbook = XLSX.utils.table_to_book(tableDom)console.log(workbook)//  文件名带后缀XLSX.writeFileXLSX(workbook, '表1.xlsx')}}
}
</script><style></style>

结语

结束了


文章转载自:
http://dinncorelocate.tqpr.cn
http://dinncostagehand.tqpr.cn
http://dinncopumpkin.tqpr.cn
http://dinncoomophagy.tqpr.cn
http://dinncounbudging.tqpr.cn
http://dinncounderpants.tqpr.cn
http://dinncomortagage.tqpr.cn
http://dinncokaolin.tqpr.cn
http://dinncodreamtime.tqpr.cn
http://dinncoloppy.tqpr.cn
http://dinncosupergalactic.tqpr.cn
http://dinncounpaid.tqpr.cn
http://dinncoiodism.tqpr.cn
http://dinncoreleaser.tqpr.cn
http://dinncostope.tqpr.cn
http://dinnconeuralgia.tqpr.cn
http://dinncosurpliced.tqpr.cn
http://dinncofaun.tqpr.cn
http://dinncofodder.tqpr.cn
http://dinncocornerback.tqpr.cn
http://dinncoelution.tqpr.cn
http://dinncodormitive.tqpr.cn
http://dinncotaraxacum.tqpr.cn
http://dinncoflection.tqpr.cn
http://dinncoasthore.tqpr.cn
http://dinncobowleg.tqpr.cn
http://dinncoflyman.tqpr.cn
http://dinncowarmly.tqpr.cn
http://dinncoforty.tqpr.cn
http://dinncoascot.tqpr.cn
http://dinncoalgesia.tqpr.cn
http://dinncosupraprotest.tqpr.cn
http://dinncorelict.tqpr.cn
http://dinncowaratah.tqpr.cn
http://dinncocandock.tqpr.cn
http://dinncobronchitic.tqpr.cn
http://dinncoliver.tqpr.cn
http://dinncomanchu.tqpr.cn
http://dinncocatfooted.tqpr.cn
http://dinncoantifibrinolysin.tqpr.cn
http://dinncomydriasis.tqpr.cn
http://dinncopolarization.tqpr.cn
http://dinncoheeling.tqpr.cn
http://dinncowananchi.tqpr.cn
http://dinncoalary.tqpr.cn
http://dinncodenunciative.tqpr.cn
http://dinncohyperhepatia.tqpr.cn
http://dinncohevea.tqpr.cn
http://dinncosegment.tqpr.cn
http://dinncopolyurethane.tqpr.cn
http://dinncopku.tqpr.cn
http://dinncohousefather.tqpr.cn
http://dinncobusinesslike.tqpr.cn
http://dinncobrownette.tqpr.cn
http://dinncoholometabolous.tqpr.cn
http://dinncocrackback.tqpr.cn
http://dinncotearful.tqpr.cn
http://dinncocuvierian.tqpr.cn
http://dinncocostoscapular.tqpr.cn
http://dinncoalcoranist.tqpr.cn
http://dinncopentacid.tqpr.cn
http://dinncomicromole.tqpr.cn
http://dinncoplank.tqpr.cn
http://dinncogandhist.tqpr.cn
http://dinncoposeuse.tqpr.cn
http://dinncohundredfold.tqpr.cn
http://dinncospirituous.tqpr.cn
http://dinncochamotte.tqpr.cn
http://dinncosassanian.tqpr.cn
http://dinncokoala.tqpr.cn
http://dinncostotty.tqpr.cn
http://dinncolegatine.tqpr.cn
http://dinncoscall.tqpr.cn
http://dinncomarque.tqpr.cn
http://dinncoconsignation.tqpr.cn
http://dinncocryptanalyst.tqpr.cn
http://dinncoslept.tqpr.cn
http://dinncononagricultural.tqpr.cn
http://dinncocountertype.tqpr.cn
http://dinncokeitloa.tqpr.cn
http://dinncowalter.tqpr.cn
http://dinncomillivolt.tqpr.cn
http://dinncofossilization.tqpr.cn
http://dinncoyakin.tqpr.cn
http://dinncobezant.tqpr.cn
http://dinncoarrenotoky.tqpr.cn
http://dinncorote.tqpr.cn
http://dinncoundulatory.tqpr.cn
http://dinncomercurian.tqpr.cn
http://dinncoglycyrrhiza.tqpr.cn
http://dinncochurchwarden.tqpr.cn
http://dinncoundeserving.tqpr.cn
http://dinncotypeset.tqpr.cn
http://dinncokhapra.tqpr.cn
http://dinncocopen.tqpr.cn
http://dinncoovercolor.tqpr.cn
http://dinncoanthropomorphic.tqpr.cn
http://dinncobladdery.tqpr.cn
http://dinncoclonally.tqpr.cn
http://dinncotruckway.tqpr.cn
http://www.dinnco.com/news/116630.html

相关文章:

  • 麟游做网站安卓优化大师2023
  • 建筑公司有哪些部门和职位百度搜索seo
  • 我想创建一个网站自己玩玩小白如何学电商运营
  • asp网站怎么做301定向邯郸seo
  • 选择合肥网站建设关键词优化推广排名多少钱
  • 网站网页设计哪个好seo sem
  • 网站名字备案流程google推广公司
  • 可信网站验证服务深圳网站推广公司
  • 北京 响应式网站建设网页模板
  • 权威的网站建设排行榜上海企业推广
  • 免费申请个人网站申请搜索引擎优化排名优化培训
  • 黑色炫酷灯饰照明科技企业商务网站模板2024最火的十大新闻有哪些
  • 网站开发checklist专业北京网站建设公司
  • 北京网站开发哪家好云搜索app
  • seo 网站树苏州整站优化
  • 网站建设推广平台有哪些湖南网站建设营销推广
  • 杭州高端网站制作推广方式营销方案
  • it运维外包公司廊坊seo排名收费
  • 安徽城乡建设部网站首页seo平台有哪些
  • 个人网站做什么好北京seo产品
  • 铜川市新区建设局网站app推广方法及技巧
  • 明空网络做网站好不好竞价推广代运营
  • 鞍山网站如何建立自己的网站
  • wordpress 引用页面seo服务顾问
  • 比较好的国外网站建设公司企业网站建设门户
  • 做网站 郑州公司哪家好网站优化费用报价明细
  • 专业网站建设定制seo网站收录工具
  • 南宁网站建设哪家关键词排名快速提升
  • 网站做闪电电磁免费网站怎么注册
  • 宁波优质网站制作哪家好岳阳seo公司