Git Product home page Git Product logo

tableexport's Introduction

tableExport.js

最近项目中做了一个table导出文件的东西,网上找了好久但是很多缺陷,要么就是很大一个库,要么就是中文乱码,于是自己弄了一下,很小,而且不会中文乱码,现在共享出来。

还很不完善,没有作太多的兼容处理,目前只做了jsontxtcsvxsl,要加pdf或者图片什么的可能要加入更多的依赖库,所以我没有做,需要的话自己加进去。

原始的代码是可以不依赖别的任何库的(jquery只是因为项目中用了所以直接写成了jquery插件的形式):

原始的代码在jquery.tableExport.js中,用法如下:

<a download="filename.json" href="javascript:;" onclick="$('#J-table').tableExport(this, 'json');">JSON</a>

通过浏览器的download属性来实现文件名设置,这个目前只有firefox和chrome支持这个属性。

tableExport.js

后来稍微作了一下修改,加入了两个依赖库:FileSaver.jsBlob.js

在导出的时候只提取table里面的文本信息,链接什么的会被过滤掉,代码也很简单,使用也很简单:

document.getElementById('xls').addEventListener('click', function(e){
	e.preventDefault();
	//tableId  filename  filetype:json txt csv doc xls
	tableExport('table1', '测试测试', 'doc');
}, false);

想用的可以下载下来根据自己的需要修改。

tableexport's People

Contributors

huanz avatar

Watchers

James Cloos avatar  avatar

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.