GithubHelp home page GithubHelp logo

excel-merge's Introduction

excel-merge

Downloads Version License

介绍

🚀 nodejs合并多个excel表

操作说明

配置环境,安装node,官网下载 node

npm install excel-merge

目录结构

simple.js
mutiple.js
demo1文件夹/
    one.xlsx
    two.xlsx
demo2文件夹
    one.xlsx
    two.xlsx

操作

simple操作

创建simple.js,内容如下,然后执行node simple.js
/* 合并多个excel表,只合并全部excel的第一页 (Sheet1) */
const merge = require('excel-merge');
//  文件 相对完整路径
const path = ['demo1/one.xlsx','demo1/two.xlsx','demo2/one.xlsx','demo2/two.xlsx'];
//  第一页(Sheet 1)的标识
const tag = ['姓名'];
merge.file(path, tag, 'simple');
/* 合并多个excel表,只合并全部excel的第一页 (Sheet 1)*/
const merge = require('excel-merge');
//  文件夹 相对路径
const path = ['demo1/','demo2/'];
//  第一页(Sheet 1)的标识
const tag = ['姓名'];
merge.dir(path, tag, 'simple');

mutiple操作

创建mutiple.js,内容如下,然后执行node mutiple.js
/* 合并多个excel表,只合并全部excel的所有页(Sheet n),建议所有excel页数相同 */
const merge = require('excel-merge');
//  文件 相对完整路径
const path = ['demo1/one.xlsx','demo1/two.xlsx','demo2/one.xlsx','demo2/two.xlsx'];
//  如果所有页(Sheet n)的标识都相同,只需要设置一个值,否则全部都要写进来
const tag = ['姓名'];
//  const tag = [tag1, tag2, tag3, tag4];
merge.file(path, tag, 'mutiple');
/* 合并多个excel表,只合并全部excel的所有页(Sheet n),建议所有excel页数相同 */
const merge = require('excel-merge');
//  文件夹 相对路径
const path = ['demo1/','demo2/'];
//  如果所有页(Sheet n)的标识都相同,只需要设置一个值,否则全部都要写进来
const tag = ['姓名'];
//  const tag = [tag1, tag2, tag3, tag4];
merge.dir(path, tag, 'mutiple');

标识说明

以下为标识,每个excel表相同页(Sheet n)都有相同的标识:'姓名'且值唯一 (不一定是'姓名',也可以选择其他的,每页的标识都可以不同)

表一 第一页(Sheet 1)

excel1.xlsx

表二 第一页(Sheet 1)

excel2.xlsx

输出dest.xlsx (Sheet 1)

dest.xlsx

函数说明

这里提供了两个函数

.file(path, tag, type)
path: <Array> 本地源多个excel文件的相对路径或者绝对路径组成的数组,必填
tag: <Array> 每个excel第一页(Sheet 1)都有的标识,作为多个excel表多页合并的依据,必填
type: <String> 'simple'和'mutiple',默认为'simple'

.dir(path, tag, type)
path: <Array> 本地源多个excel文件夹组成的数组,获取文件夹下所有excel表,必填
tag: <Array> 每个excel每页(Sheet n)都有的标识,作为多个excel表多页合并的依据,必填
    (如果每页的tag相同,则数组只设置一个值即可)
type: <String> 'simple'和'mutiple',默认为'simple'

功能说明

simple操作
1.合并多个excel表到一个新的excel表
2.只合并所有excel表的第一页
3.不影响源文件

mutiple操作
1.合并多个excel表到一个新的excel表
2.只合并所有excel表的所有页
3.不影响源文件

输出文档

下载后你的文件夹会出现
dest.xlsx: 合并多个excel文件之后的新excel文件

注意事项

目前只支持xlsx文件格式
所有excel表页数(Sheet n)相同,否则mutiple只能合并所有表格共有的前n页(Sheet n)
每一页(Sheet n)必须有一个相同标识,标识最好具有唯一性
标识选择excel表第一行标题中的随意一个
excel表内容尽量不要冲突,如果发生冲突,以靠前的表为标准

作者:微博 @itagn - Github @itagn

excel-merge's People

Contributors

itagn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

excel-merge's Issues

合并时的Sheet页名称相同但顺序不同,合并异常

Mac版的Excel非常需要这个工具,感谢!

使用中有个小问题:多个Excel文件虽然是相同的两个Sheet页,但是顺序不同,比如excel1.xlsx里面两页是A、B的顺序,excel2.xlsx里面两页是B、A的顺序。

A、B两页的字段不太相同,但合并时也没有报错。

希望的是能够按Sheet页的名称对应合并,这个小逻辑应该是一个合理的容错吧,还请评估!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.