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

工作室赚钱项目宁波seo网络推广服务商

工作室赚钱项目,宁波seo网络推广服务商,企业形象设计的意义,百度seo技术目录 1. 项目初始化与依赖安装2. 表格组件设计(基于 Handsontable)3. 导入功能:支持 .xlsx / .csv4. 导出功能:带样式 & 合并信息5. 样式同步实现方案6. 合并单元格功能逻辑7. 拓展功能建议 示例代码✅ 设置单元格背景色按钮…

目录

  • 1. 项目初始化与依赖安装
  • 2. 表格组件设计(基于 Handsontable)
  • 3. 导入功能:支持 `.xlsx` / `.csv`
  • 4. 导出功能:带样式 & 合并信息
  • 5. 样式同步实现方案
  • 6. 合并单元格功能逻辑
  • 7. 拓展功能建议 + 示例代码
    • ✅ 设置单元格背景色按钮
    • ✅ 支持 JSON 数据导出保存

1. 项目初始化与依赖安装

npm init vite@latest excel-editor --template vue-ts  
cd excel-editor  
npm install  
npm install xlsx file-saver handsontable @handsontable/vue  
npm install -D tailwindcss postcss autoprefixer  
npx tailwindcss init -p  

main.ts 中引入 Tailwind:

import './index.css'  

2. 表格组件设计(基于 Handsontable)

我们封装一个 ExcelEditor.vue 组件,使用 @handsontable/vue

<template>  <hot-table  ref="hotTableRef"  :settings="settings"  licenseKey="non-commercial-and-evaluation"  />  
</template>  <script setup lang="ts">  
import { ref } from 'vue'  
import { HotTable } from '@handsontable/vue'  
import Handsontable from 'handsontable'  const hotTableRef = ref()  
const settings = {  data: Handsontable.helper.createEmptySpreadsheetData(20, 10),  rowHeaders: true,  colHeaders: true,  contextMenu: true,  mergeCells: [],  manualRowResize: true,  manualColumnResize: true,  comments: true,  cells(row: number, col: number) {  return { className: '' }  }  
}  
</script>  

3. 导入功能:支持 .xlsx / .csv

import * as XLSX from 'xlsx'  const handleFileUpload = (file: File) => {  const reader = new FileReader()  reader.onload = (e) => {  const data = new Uint8Array(e.target!.result as ArrayBuffer)  const workbook = XLSX.read(data, { type: 'array' })  const sheet = workbook.Sheets[workbook.SheetNames[0]]  const json = XLSX.utils.sheet_to_json(sheet, { header: 1 })  hotTableRef.value.hotInstance.loadData(json)  }  reader.readAsArrayBuffer(file)  
}  

4. 导出功能:带样式 & 合并信息

import { saveAs } from 'file-saver'  const exportToExcel = () => {  const hot = hotTableRef.value.hotInstance  const data = hot.getData()  const ws = XLSX.utils.aoa_to_sheet(data)  const merges = hot.getPlugin('mergeCells').mergedCellsCollection.mergedCells  ws['!merges'] = merges.map(m => ({  s: { r: m.row, c: m.col },  e: { r: m.row + m.rowspan - 1, c: m.col + m.colspan - 1 }  }))  const wb = XLSX.utils.book_new()  XLSX.utils.book_append_sheet(wb, ws, 'Sheet1')  const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' })  saveAs(new Blob([wbout]), 'table.xlsx')  
}  

5. 样式同步实现方案

const cellStyles = new Map<string, any>()  const updateCellStyle = (row: number, col: number, style: any) => {  const key = `${row}_${col}`  cellStyles.set(key, style)  
}  cells(row, col) {  const key = `${row}_${col}`  const style = cellStyles.get(key) || {}  return {  renderer(hotInstance, td, row, col, prop, value) {  td.style.backgroundColor = style.backgroundColor || ''  td.style.fontWeight = style.fontWeight || ''  td.innerText = value  return td  }  }  
}  

6. 合并单元格功能逻辑

const mergeSelectedCells = () => {  const hot = hotTableRef.value.hotInstance  const selected = hot.getSelectedLast()  if (!selected) return  const [startRow, startCol, endRow, endCol] = selected  hot.getPlugin('mergeCells').merge({  row: Math.min(startRow, endRow),  col: Math.min(startCol, endCol),  rowspan: Math.abs(endRow - startRow) + 1,  colspan: Math.abs(endCol - startCol) + 1,  })  hot.render()  
}  

7. 拓展功能建议 + 示例代码

✅ 设置单元格背景色按钮

<button @click="setCurrentCellStyle({ backgroundColor: '#ffff99' })">  高亮当前单元格  
</button>  const setCurrentCellStyle = (style: any) => {  const hot = hotTableRef.value.hotInstance  const [row, col] = hot.getSelectedLast() || []  updateCellStyle(row, col, style)  hot.render()  

✅ 支持 JSON 数据导出保存

const getJsonData = () => {  const data = hotTableRef.value.hotInstance.getData()  return JSON.stringify(data)  
}  

到这里,这篇文章就和大家说再见啦!我的主页里还藏着很多 篇 前端 实战干货,感兴趣的话可以点击头像看看,说不定能找到你需要的解决方案~
创作这篇内容花了很多的功夫。如果它帮你解决了问题,或者带来了启发,欢迎:
点个赞❤️ 让更多人看到优质内容
关注「前端极客探险家」🚀 每周解锁新技巧
收藏文章⭐️ 方便随时查阅
📢 特别提醒:
转载请注明原文链接,商业合作请私信联系
感谢你的阅读!我们下篇文章再见~ 💕

在这里插入图片描述


文章转载自:

http://hIWEiR5G.tymnr.cn
http://COhXBwC4.tymnr.cn
http://Bp7pFOAm.tymnr.cn
http://CMo1LKOv.tymnr.cn
http://cR3kb98x.tymnr.cn
http://fDfcntN0.tymnr.cn
http://afQPBPVD.tymnr.cn
http://EGqY17Dt.tymnr.cn
http://uWtEBHeP.tymnr.cn
http://CwifHxdd.tymnr.cn
http://pOgHVFv6.tymnr.cn
http://pyMnwpR7.tymnr.cn
http://yVH0bPA6.tymnr.cn
http://2DUR4AGA.tymnr.cn
http://QGkXIxqZ.tymnr.cn
http://fal3K2py.tymnr.cn
http://lwa9eWDE.tymnr.cn
http://sYjCpH6Y.tymnr.cn
http://x2i9K1UJ.tymnr.cn
http://2gKnWZFe.tymnr.cn
http://hm0fYPM0.tymnr.cn
http://U0IYnufX.tymnr.cn
http://W5svK43n.tymnr.cn
http://BIXY3v6w.tymnr.cn
http://fVvq8OPa.tymnr.cn
http://KBGKOgak.tymnr.cn
http://vHaYLMJw.tymnr.cn
http://z2KE7XN9.tymnr.cn
http://7yiDJOp7.tymnr.cn
http://UI1UYcSY.tymnr.cn
http://www.dtcms.com/wzjs/719935.html

相关文章:

  • seo站长优化工具wordpress安装界面默认英文
  • 梦创义网站建设公司网页新建站点
  • 烟台网站seo网站推广办法
  • 网站解析怎么设置o2o新零售系统
  • 东莞网络公司网站建设wordpress 返回 插件
  • 怎样在百度上做网站长沙企业网站制作
  • 汽车行业市场分析那个网站做的好家用电脑怎么做网站
  • 苍溪建设局网站网站制作与网站建设实际报告
  • 廊坊手机网站wordpress映射到外网访问
  • 动易网站后台管理功能中国网络安全官网
  • 公众号里链接的网站怎么做的运营说白了是什么意思
  • 怎样做网站上的语种链接开发软件多少钱一个月
  • 制作网站要找什么公司广州注册公司必看
  • 宠物医院网站建设方案wordpress 客户端配置文件
  • 做网站工作室安陆网站建设推广
  • 免费推广网站下载做知识产权服务的网站
  • 上海市建设注册管理网站深圳小程序开发官网
  • 网站打不开什么原因大淘客网站建设app
  • 苏州外贸网站在线生成头像
  • fireworks8做网站调用wordpress分类名称
  • 手机网站布局wordpress ovz安装
  • 网站 防止采集做的网站为什么图片看不了怎么回事
  • mysql 注册网站试用网站建设
  • 商业网站设计方案模板线上营销的优势和劣势
  • 建设工程规范下载网站wordpress富编辑器
  • 永州微网站建设内蒙古住房和城乡建设部网站
  • 怎么创网站赚钱制作电商网站
  • 网站logo设计制作东莞专业建站公司费用
  • 天目建设集团 网站东莞建设工程招标网
  • 中融木业网站是那个网站做的瓷砖网站建设