npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eltable-as-xlsx

v1.0.5

Published

下载el-table为xlsx

Downloads

15

Readme

eltable-as-xlsx 介绍

eltable-as-xlsx 是为了解决导出el-table(elementPlus)数据的小插件

环境

vue3 、 elementPlus

使用说明

// 安装依赖
npm i eltable-as-xlsx -D

// 引入
import { exportExcel } from "eltable-as-xlsx";


exportExcel({
    id: tableId,  // 字符串  当前要下载的el-tableID
    fileName: `file-${new Date().getTime()}`, // 字符串 要导出的xlsx文件名称
    excludeColumns: props.excludeDownloadColumns, // 数组  导出时候要排除的数据
  });

截图 : Alt text

举个栗子


<template>
  <el-table
    id="el-t"
    :data="tableData"
    style="width: 100%"
    @header-contextmenu="handleRightClick">
    <el-table-column label="日期" prop="date" />
    <el-table-column label="姓名" prop="name" />
    <el-table-column label="操作">
      <template #default="scope">
        <el-button size="small">Edit</el-button>
        <el-button size="small" type="danger">Delete</el-button>
      </template>
    </el-table-column>
  </el-table>

  <div
    v-if="contextMenuVisible"
    class="context-menu"
    :style="contextMenuStyle">
    <div class="context-menu-option" @click="exportExcelFun">导出为excel</div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { exportExcel } from "eltable-as-xlsx";

interface User {
  date: string;
  name: string;
  address: string;
}

const tableData: User[] = [
  {
    date: "2016-05-03",
    name: "Tom",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-02",
    name: "John",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-04",
    name: "Morgan",
    address: "No. 189, Grove St, Los Angeles",
  },
  {
    date: "2016-05-01",
    name: "Jessy",
    address: "No. 189, Grove St, Los Angeles",
  },
];

const contextMenuVisible = ref(false);
// 右键菜单的位置
const contextMenuStyle = ref({
  left: "0",
  top: "0",
});

//
function handleRightClick(column: any, event: any) {
  event.preventDefault();
  // 获取鼠标位置
  let x = event.pageX;
  let y = event.pageY;
  contextMenuVisible.value = true;
  contextMenuStyle.value = {
    left: `${x}px`,
    top: `${y}px`,
  };
  // 三秒不操作就自动清空
  setTimeout(() => {
    contextMenuVisible.value = false;
  }, 3000);
}

function exportExcelFun() {
  exportExcel({
    id: "el-t", // DOM  id
    fileName: `file-${new Date().getTime()}`, // xlsx文件名
    excludeColumns: ["操作"], // 要过滤的列
  });
  contextMenuVisible.value = false;
}
</script>
<style>
.context-menu {
  position: fixed;

  background-color: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
  z-index: 999;
  border: 1px solid #ccc;
}

.context-menu-option {
  padding: 4px 15px;
  white-space: nowrap;
  cursor: pointer;
  font-size: 12px;
}

.context-menu-option:hover {
  background-color: #f5f5f5;
}
</style>