使用 vxe-table 来格式化任意的金额格式,支持导出与复制单元格格式到 excel

news2025/5/22 8:28:30

使用 vxe-table 来格式化任意的金额格式,支持导出与复制单元格格式到 excel

查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table

安装

npm install vxe-pc-ui@4.5.23 vxe-table@4.13.4
import VxeUIAll from 'vxe-pc-ui'
import 'vxe-pc-ui/lib/style.css'
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'

createApp(App).use(VxeUIAll).use(VxeUITable).mount('#app')

格式化金额

通过内置的 FormatNumberInput 格式化数值渲染器,配置 type = amount 为货币类型就可以了

在这里插入图片描述

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'

const gridOptions = reactive({
  border: true,
  height: 500,
  showOverflow: true,
  columns: [
    { type: 'seq', width: 60 },
    { field: 'name', title: '名字' },
    { field: 'num1', title: '货币类型', align: 'right', cellRender: { name: 'FormatNumberInput', props: { type: 'amount', align: 'right' } } },
    { field: 'num2', title: '货币类型(带货币符号)', align: 'right', cellRender: { name: 'FormatNumberInput', props: { type: 'amount', align: 'right', showCurrency: true } } },
    { field: 'num3', title: '货币类型(负数自动标红)', align: 'right', cellRender: { name: 'FormatNumberInput', showNegativeStatus: true, props: { type: 'amount', align: 'right', showCurrency: true } } }
  ],
  data: [
    { id: 10001, name: '张三', code1: '0002365', code2: '0002365', num1: -3.56, num2: -3.56, num3: -3.56, num4: -3.56, str1: '10,000,000.00', str2: '10,000,000.00' },
    { id: 10002, name: '李四', code1: '0002465', code2: '0002465', num1: 1, num2: 1, num3: 1, num4: 1, str1: '90,000,000.00', str2: '90,000,000.00' },
    { id: 10003, name: '老六', code1: '0002567', code2: '0002567', num1: 1235640, num2: 1235640, num3: 1235640, num4: 1235640, str1: '100,000', str2: '100,000' },
    { id: 10004, name: '小李', code1: '0678865', code2: '0678865', num1: -96300000.4, num2: -96300000.4, num3: -96300000.4, num4: -96300000.4, str1: '', str2: '' },
    { id: 10005, name: '老万', code1: '23470565', code2: '23470565', num1: 240.63, num2: 240.63, num3: 240.63, num4: 240.63, str1: '', str2: '' },
    { id: 10006, name: '小刘', code1: '086222135', code2: '086222135', num1: 0.1, num2: 0.1, num3: 0.1, num4: 0.1, str1: '', str2: '' },
    { id: 10007, name: '老徐', code1: '3600665', code2: '3600665', num1: 0, num2: 0, num3: 0, num4: 0, str1: '330.02', str2: '330.02' },
    { id: 10008, name: '老二', code1: '009635', code2: '009635', num1: null, num2: null, num3: null, num4: null, str1: '10,000,000.33', str2: '10,000,000.33' },
    { id: 10009, name: '小牛', code1: '09034523', code2: '09034523', num1: 100000000, num2: 100000000, num3: 100000000, num4: 100000000, str1: '', str2: '' },
    { id: 10010, name: '小帅', code1: '872220222', code2: '872220222', num1: null, num2: null, num3: null, num4: null, str1: '1,230.30', str2: '1,230.30' },
    { id: 10011, name: '老魏', code1: '10022354', code2: '10022354', num1: 96342, num2: 96342, num3: 96342, num4: 96342, str1: '', str2: '' },
    { id: 10012, name: '小徐', code1: '0009785', code2: '0009785', num1: -740000, num2: -740000, num3: -740000, num4: -740000, str1: '', str2: '' }
  ]
})
</script>

导出到 excel

支持导出分组表头、合并、单元格类型、导出图片等格式
在这里插入图片描述

<template>
  <div>
    <vxe-button status="primary" @click="exportEvent">高级导出</vxe-button>
    <vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue';

const gridRef = ref();

const imgUrlCellRender = reactive({
    name: 'VxeImage',
    props: {
        width: 36,
        height: 36
    }
});

const gridOptions = reactive({
    border: true,
    showFooter: true,
    showOverflow: true,
    editConfig: {
        trigger: 'click',
        mode: 'cell'
    },
    mergeCells: [
        { row: 0, col: 2, rowspan: 1, colspan: 2 },
        { row: 2, col: 2, rowspan: 2, colspan: 1 }
    ],
    exportConfig: {
        type: 'xlsx'
    },
    columns: [
        { field: 'checkbox', type: 'checkbox', width: 70 },
        { field: 'seq', type: 'seq', width: 70 },
        { field: 'name', title: 'Name', editRender: { name: 'VxeInput' } },
        { field: 'code', title: '字符串类型', cellType: 'string', editRender: { name: 'VxeInput' } },
        {
            title: '分组1',
            children: [
                { field: 'num1', title: '数值', editRender: { name: 'VxeNumberInput', props: { type: 'float' } } },
                { field: 'num2', title: '数值(负数标红)', editRender: { name: 'VxeNumberInput', showNegativeStatus: true, props: { type: 'float' } } }
            ]
        },
        { field: 'amount1', title: '货币', editRender: { name: 'VxeNumberInput', props: { type: 'amount', showCurrency: true } } },
        { field: 'amount2', title: '货币(负数标红)', editRender: { name: 'VxeNumberInput', showNegativeStatus: true, props: { type: 'amount', showCurrency: true } } },
        { field: 'imgUrl', title: '图片', width: 80, cellRender: imgUrlCellRender }
    ],
    data: [
        { id: 10001, name: '张三', code: '000528697411', num1: 0.32, num2: -0.11, amount1: 1000000000, amount2: -0.11, imgUrl: 'https://vxeui.com/resource/img/fj586.png' },
        { id: 10002, name: '李四', code: '001236598563', num1: null, num2: 100000, amount1: -990000, amount2: 4, imgUrl: 'https://vxeui.com/resource/img/fj573.jpeg' },
        { id: 10003, name: '王五', code: '001499675653', num1: 100000, num2: null, amount1: 1, amount2: 100000, imgUrl: 'https://vxeui.com/resource/img/fj567.jpeg' },
        { id: 10004, name: '老六', code: '002568967545', num1: -0.11, num2: 1000000000, amount1: null, amount2: 1000000000, imgUrl: 'https://vxeui.com/resource/img/fj577.jpg' },
        { id: 10005, name: '小七', code: '005233368777', num1: -990000, num2: 28, amount1: 100000, amount2: null, imgUrl: 'https://vxeui.com/resource/img/bq673.gif' },
        { id: 10006, name: '小八', code: '000369877575', num1: 1000000000, num2: -990000, amount1: -0.11, amount2: -990000, imgUrl: 'https://vxeui.com/resource/img/fj124.jpeg' }
    ],
    footerData: [
        { checkbox: '合计', name: '12人', no1: 356 }
    ]
});

const exportEvent = () => {
    const $grid = gridRef.value;
    if ($grid) {
        $grid.openExport();
    }
};
</script>

复制到 excel(企业版)

在这里插入图片描述

<template>
  <div>
    <vxe-grid v-bind="gridOptions"></vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'

const gridOptions = reactive({
  border: true,
  height: 500,
  showOverflow: true,
  mouseConfig: {
    area: true // 是否开启区域选取
  },
  keyboardConfig: {
    isClip: true,
    isArrow: true,
    isShift: true,
    isTab: true,
    isEnter: true,
    isFNR: true // 是否开启查找与替换
  },
  columns: [
    { type: 'seq', width: 60 },
    { field: 'name', title: '名字' },
    { field: 'num1', title: '货币类型', align: 'right', cellRender: { name: 'FormatNumberInput', props: { type: 'amount', align: 'right' } } },
    { field: 'num2', title: '货币类型(带货币符号)', align: 'right', cellRender: { name: 'FormatNumberInput', props: { type: 'amount', align: 'right', showCurrency: true } } },
    { field: 'num3', title: '货币类型(负数自动标红)', align: 'right', cellRender: { name: 'FormatNumberInput', showNegativeStatus: true, props: { type: 'amount', align: 'right', showCurrency: true } } }
  ],
  data: [
    { id: 10001, name: '张三', code1: '0002365', code2: '0002365', num1: -3.56, num2: -3.56, num3: -3.56, num4: -3.56, str1: '10,000,000.00', str2: '10,000,000.00' },
    { id: 10002, name: '李四', code1: '0002465', code2: '0002465', num1: 1, num2: 1, num3: 1, num4: 1, str1: '90,000,000.00', str2: '90,000,000.00' },
    { id: 10003, name: '老六', code1: '0002567', code2: '0002567', num1: 1235640, num2: 1235640, num3: 1235640, num4: 1235640, str1: '100,000', str2: '100,000' },
    { id: 10004, name: '小李', code1: '0678865', code2: '0678865', num1: -96300000.4, num2: -96300000.4, num3: -96300000.4, num4: -96300000.4, str1: '', str2: '' },
    { id: 10005, name: '老万', code1: '23470565', code2: '23470565', num1: 240.63, num2: 240.63, num3: 240.63, num4: 240.63, str1: '', str2: '' },
    { id: 10006, name: '小刘', code1: '086222135', code2: '086222135', num1: 0.1, num2: 0.1, num3: 0.1, num4: 0.1, str1: '', str2: '' },
    { id: 10007, name: '老徐', code1: '3600665', code2: '3600665', num1: 0, num2: 0, num3: 0, num4: 0, str1: '330.02', str2: '330.02' },
    { id: 10008, name: '老二', code1: '009635', code2: '009635', num1: null, num2: null, num3: null, num4: null, str1: '10,000,000.33', str2: '10,000,000.33' },
    { id: 10009, name: '小牛', code1: '09034523', code2: '09034523', num1: 100000000, num2: 100000000, num3: 100000000, num4: 100000000, str1: '', str2: '' },
    { id: 10010, name: '小帅', code1: '872220222', code2: '872220222', num1: null, num2: null, num3: null, num4: null, str1: '1,230.30', str2: '1,230.30' },
    { id: 10011, name: '老魏', code1: '10022354', code2: '10022354', num1: 96342, num2: 96342, num3: 96342, num4: 96342, str1: '', str2: '' },
    { id: 10012, name: '小徐', code1: '0009785', code2: '0009785', num1: -740000, num2: -740000, num3: -740000, num4: -740000, str1: '', str2: '' }
  ]
})
</script>

https://gitee.com/x-extends/vxe-table

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2336895.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

金币捕鱼类手游《海洋管家》源码结构与系统分层解析

在休闲互动类移动应用开发中&#xff0c;捕鱼类项目因玩法成熟、逻辑清晰而成为不少开发者接触多端架构与模块化管理的重要起点。本文以一款名为《海洋管家》的项目源码为样例&#xff0c;简要解析其整体结构与主要功能模块&#xff0c;供有类似项目需求或系统学习目的的开发者…

Go语言实现OAuth 2.0认证服务器

文章目录 1. 项目概述1.1 OAuth2 流程 2. OAuth 2.0 Storage接口解析2.1 基础方法2.2 客户端管理相关方法2.3 授权码相关方法2.4 访问令牌相关方法2.5 刷新令牌相关方法 2.6 方法调用时序2.7 关键注意点3. MySQL存储实现原理3.1 数据库设计3.2 核心实现 4. OAuth 2.0授权码流程…

【2025年认证杯数学中国数学建模网络挑战赛】C题 数据预处理与问题一二求解

目录 【2025年认证杯数学建模挑战赛】C题数据预处理与问题一求解三、数据预处理及分析3.1 数据可视化3.2 滑动窗口相关系数统计与动态置信区间耦合分析模型3.3 耦合关系分析结果 四、问题一代码数据预处理问题一 【2025年认证杯数学建模挑战赛】C题 数据预处理与问题一求解 三…

2025年最新Web安全(面试题)

活动发起人小虚竹 想对你说&#xff1a; 这是一个以写作博客为目的的创作活动&#xff0c;旨在鼓励大学生博主们挖掘自己的创作潜能&#xff0c;展现自己的写作才华。如果你是一位热爱写作的、想要展现自己创作才华的小伙伴&#xff0c;那么&#xff0c;快来参加吧&#xff01…

开源微调混合推理模型:cogito-v1-preview-qwen-32B

一、模型概述 1.1 模型特点 Cogito v1-preview-qwen-32B 是一款基于指令微调的生成式语言模型&#xff08;LLM&#xff09;&#xff0c;具有以下特点&#xff1a; 支持直接回答&#xff08;标准模式&#xff09;和自我反思后再回答&#xff08;推理模式&#xff09;。使用 I…

Golang|Channel 相关用法理解

文章目录 用 channel 作为并发小容器channel 的遍历channel 导致的死锁问题用 channel 传递信号用 channel 并行处理文件用channel 限制接口的并发请求量用 channel 限制协程的总数量 用 channel 作为并发小容器 注意这里的 ok 如果为 false&#xff0c;表示此时不仅channel为空…

C++ - #命名空间 #输入、输出 #缺省参数 #函数重载 #引用 # const 引用 #inline #nullptr

文章目录 前言 一、实现C版本的hello world 二、命名空间 1、namespace 的价值 2、namespace 的定义 (1.域会影响一个编译器编译语法时的查找规则 (2、域会影响生命周期 (3、命名空间域只能定义在全局 (4、编译器会自动合并相同命名空间中的内容 (5、C标准库放在命名…

JSON处理工具/框架的常见类型及详解,以Java语言为例

以下是JSON处理工具/框架的常见类型及详解&#xff0c;以Java语言为例&#xff1a; 一、主流JSON处理工具对比 Jackson&#xff08;推荐&#xff09; 特点&#xff1a;高性能、功能丰富&#xff0c;支持注解&#xff08;如JsonProperty&#xff09;、树形模型&#xff08;Json…

中间件--ClickHouse-1--基础介绍(列式存储,MPP架构,分布式计算,SQL支持,向量化执行,亿万级数据秒级查询)

1、概述 ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS)。它由俄罗斯的互联网巨头Yandex为解决其内部数据分析需求而开发&#xff0c;并于2016年开源。专为大规模数据分析&#xff0c;实时数据分析和复杂查询设计&#xff0c;具有高性能、实时数据和可扩展性等…

Java中的经典排序算法:插入排序、希尔排序、选择排序、堆排序与冒泡排序(如果想知道Java中有关插入排序、希尔排序、选择排序、堆排序与冒泡排序的知识点,那么只看这一篇就足够了!)

前言&#xff1a;排序算法是计算机科学中的基础问题之一&#xff0c;它在数据处理、搜索算法以及各种优化问题中占有重要地位&#xff0c;本文将详细介绍几种经典的排序算法&#xff1a;插入排序、选择排序、堆排序和冒泡排序。 ✨✨✨这里是秋刀鱼不做梦的BLOG ✨✨✨想要了解…

K8S+Prometheus+Consul+alertWebhook实现全链路服务自动发现与监控、告警配置实战

系列文章目录 k8s服务注册到consul prometheus监控标签 文章目录 系列文章目录前言一、环境二、Prometheus部署1.下载2.部署3.验证 三、kube-prometheus添加自定义监控项1.准备yaml文件2.创建新的secret并应用到prometheus3.将yaml文件应用到集群4.重启prometheus-k8s pod5.访…

uniapp-商城-25-顶部模块高度计算

计算高度&#xff1a; 使用computed进行顶部模块的计算。 总高度&#xff1a;bartotalHeight log 介绍--收款码这一条目 也就是上一章节的title的高度计算 bodybarheight。 在该组件中&#xff1a; js部分的代码&#xff1a; 包含了导出的名字&#xff1a; shop-head…

非关系型数据库(NoSQL)与 关系型数据库(RDBMS)的比较

非关系型数据库&#xff08;NoSQL&#xff09;与 关系型数据库&#xff08;RDBMS&#xff09;的比较 一、引言二、非关系型数据库&#xff08;NoSQL&#xff09;2.1 优势 三、关系型数据库&#xff08;RDBMS&#xff09;3.1 优势 四、结论 &#x1f496;The Begin&#x1f496;…

蓝桥杯2024国B数星星

小明正在一棵树上数星星&#xff0c;这棵树有 n 个结点 1,2,⋯,n。他定义树上的一个子图 G 是一颗星星&#xff0c;当且仅当 G 同时满足&#xff1a; G 是一棵树。G 中存在某个结点&#xff0c;其度数为 ∣VG​∣−1。其中 ∣VG​∣ 表示这个子图含有的结点数。 两颗星星不相…

中科院1区顶刊Expert Systems with Applications ESO:增强型蛇形算法,性能不错

Snake Optimizer&#xff08;SO&#xff09;是一种优化效果良好的新颖算法&#xff0c;但由于自然规律的限制&#xff0c;在探索和开发阶段参数更多是固定值&#xff0c;因此SO算法很快陷入局部优化并慢慢收敛。本文通过引入新颖的基于对立的学习策略和新的动态更新机制&#x…

Flask+Influxdb+grafna构建电脑性能实时监控系统

Influx下载地址&#xff0c;这里下载了以下版本influxdb-1.8.5_windows_amd64.zip 运行前需要先启动Influx数据库&#xff1a; 管理员方式运行cmd->F:->cd F:\influxdb\influxdb-1.8.5-1->influxd -config influxdb.conf&#xff0c;以influxdb.conf配置文件启动数…

若伊微服务版本教程(自参)

第一步 若伊官网下载源码 https://ruoyi.vip/ RuoYi-Cloud: &#x1f389; 基于Spring Boot、Spring Cloud & Alibaba的分布式微服务架构权限管理系统&#xff0c;同时提供了 Vue3 的版本 git clone 到 本地 目录如下&#xff1a; 第二部 参考官网 运行部署说明 环境部署…

ESP32与STM32哪种更适合初学者?

目录 1、ESP32&#xff1a;物联网时代的“网红” 2、STM32&#xff1a;工业界的“常青树” 3、到底谁更容易&#xff1f; 无论是刚入坑的小白&#xff0c;还是想扩展技术栈的老鸟&#xff0c;在选择主力 MCU 时&#xff0c;学习曲线绝对是重要的考量因素。ESP32 以其强大的 …

秒杀秒抢系统开发:飞算 JavaAI 工具如何应对高并发难题?

秒杀、秒抢活动已成为电商促销与吸引流量的常用手段。然而&#xff0c;此类活动所带来的高并发访问&#xff0c;对系统性能构成了巨大挑战。如何确保系统在高并发场景下依然能够稳定、高效运行&#xff0c;成为开发者亟待解决的关键问题。飞算 JavaAI 工具作为一款功能强大的开…

C# 将Excel格式文件导入到界面中,用datagridview显示

界面按钮不做介绍。 主要代码: //用于获取从上一个页面传过来datagridview标题 public DataTable GetHeader { get; set; } private void UI_EXPINFO_Load(object sender, EventArgs e) { //页面加载显示listbox1中可…