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

ksc-component-export-files

v1.0.2

Published

Excel file import and export tools

Downloads

8

Readme

文件导出、导出工具

  • 支持 Excel 、CSV 文件导入
  • 支持 Excel 、CSV、Word 导出

安装

npm i ksc-component-export-files
# 或者 
npm install git+http://newgit.op.ksyun.com/ksc-cns-fe/ksc-component-export-files.git --save 

使用

文件导出

var output = [
    ['标题1','标题2','标题3','标题4'],
    ['数据1','数据2','数据3','数据4'],
    ....
    ['数据1N','数据2N','数据3N','数据4N'],
]

// 推荐:方式一 
import { exportFile } from 'ksc-component-export-files'
exportFile(output ,'文件名-' + Date.now()  , "csv" )

// 方式二 
import kscComponentExportFiles from 'ksc-component-export-files';
kscComponentExportFiles(output ,'文件名-' + Date.now()  , "csv" )

文件导入 异步方式

input( type = 'file' 
accept = ".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
 @click = "upload" id = 'uploadFile' ) 

// Html Input
import { importFile } from 'ksc-component-export-files'

const files = document.getElementById('uploadFile') as any 
let reader = new FileReader();
reader.readAsArrayBuffer(files.files[0]) as any 
reader.onload = function( event ){
  // 这里的this 指向 global.this : FileReader
  let result = this.result 
  // let result =  event.target.value  ; // 也可以获取result 
  importFile( result ).then( (data : any  ) =>{
        console.log( data )
    })
}
// Element-ui  
 el-upload(
    action = '#'
    ref = 'upload'
    :on-change="handleChange"
    :on-success = "handleSuccess"
    :on-exceed="handleExceed"
    :limit = '1'
    :file-list="fileList"
    accept = '.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
)   
    el-button 导入列表   

// js 
  handleChange(file , fileList ){
    this.fileList = fileList ;
    const reader = new FileReader();
    reader.readAsBinaryString( file.raw )
    reader.onload = function(  ev ){
        let result = ev.target.result ; 
        importFile( result , {
            type: 'binary',
            cellDates: true ,
        }).then( (data) =>{
            console.log( JSON.stringify(data) )
        })
    }

  },

importFile 方法参数

| param | type | default | |:--|:--|:--| | data | any | '' | | opts | Object : ParsingOptions | {type: 'binary', cellDates: true}} |

  // ParsingOptions Params
export interface ParsingOptions{
    /** Input data encoding */
    type?: 'base64' | 'binary' | 'buffer' | 'file' | 'array' | 'string';

    /** Default codepage */
    codepage?: number;

    /**
     * Save formulae to the .f field
     * @default true
     */
    cellFormula?: boolean;

    /**
     * Parse rich text and save HTML to the .h field
     * @default true
     */
    cellHTML?: boolean;

    /**
     * Save number format string to the .z field
     * @default false
     */
    cellNF?: boolean;

    /**
     * Generate formatted text to the .w field
     * @default true
     */
    cellText?: boolean;

    /** Override default date format (code 14) */
    dateNF?: string;

    /**
     * If >0, read the first sheetRows rows
     * @default 0
     */
    sheetRows?: number;

    /**
     * If true, parse calculation chains
     * @default false
     */
    bookDeps?: boolean;

    /**
     * If true, add raw files to book object
     * @default false
     */
    bookFiles?: boolean;

    /**
     * If true, only parse enough to get book metadata
     * @default false
     */
    bookProps?: boolean;

    /**
     * If true, only parse enough to get the sheet names
     * @default false
     */
    bookSheets?: boolean;

    /** If specified, only parse the specified sheets or sheet names */
    sheets?: number | string | Array<number | string>;

    /** If true, plaintext parsing will not parse values */
    raw?: boolean;

    dense?: boolean;
}