當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript xlsx.read函數代碼示例

本文整理匯總了TypeScript中xlsx.read函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript read函數的具體用法?TypeScript read怎麽用?TypeScript read使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了read函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: while

        return new Promise<any>((resolve, reject) => {
            this.workbooks = [];
            for (let file of inputData) {
                this.workbooks.push(xlsx.read(file, {"type": "buffer"}));
            }

            let workbook = this.workbooks.pop();
            while (workbook != null) {
                workbook.SheetNames.forEach((sheetName) => {
                    let worksheet = workbook.Sheets[sheetName];
                    let worksheetAsJson = xlsx.utils.sheet_to_json(worksheet);

                    let keys = [];
                    worksheetAsJson.forEach((item) => {
                        for(var k in item)
                            if(!keys.includes(k))
                                keys.push(k);
                    });

                    let properties = {};
                    for(let i=0; i<keys.length; i++)
                        properties[keys[i]] = {"type": "string"};

                    this.schema.toObject().properties[sheetName] = {"type": "array", "items":{"type": "object", "properties":properties}};
                });

                // next workbook
                workbook = this.workbooks.pop();
            }

            resolve();
        });
開發者ID:sebischair,項目名稱:syncpipes-server,代碼行數:32,代碼來源:service.ts

示例2: Transform

export function Transform (buffer, options) {
  let meta = options.meta || false;

  let offset = options.offset || 0;
  let excel = XLSX.read(buffer, {binary:true, bookProps: meta});

  if (meta === true) {
    return excel.Props;
  }

  let sheets = excel.Sheets,
    sheet, k;

  let output = [];
  for (k in sheets) {
    sheet = sheets[k];

    let json = sheet_to_json(sheet, {
      raw: false
    });
    output.push(json);
  }

  output = flatten(output)
  if (offset >= output.length) {
    output = [];
  } else {
    output = output.slice(offset, output.length);
  }
  return output;
};
開發者ID:kildevaeld,項目名稱:pipe2,代碼行數:31,代碼來源:transform.ts

示例3: prepare

 prepare(context: SyncPipes.IPipelineContext, logger: SyncPipes.ILogger): Promise<any> {
     this.context = context;
     this.workbooks = [];
     // load xlsx file(s) from context
     for (let file of context.inputData) {
         this.workbooks.push(xlsx.read(file, {"type": "buffer"}));
     }
     // resolve immediately, since no async work is done
     return Promise.resolve();
 }
開發者ID:sebischair,項目名稱:syncpipes-server,代碼行數:10,代碼來源:service.ts

示例4:

	cellDates: false,
	bookSST: false,
	bookType: "xlsx",
	sheet: "Sheet1",
	compression: false,
	Props: {
		Author: "Someone",
		Company: "SheetJS LLC"
	}
};

const wb1 = XLSX.readFile("sheetjs.xls", read_opts);
XLSX.writeFile(wb1, "sheetjs.new.xlsx", write_opts);

read_opts.type = "binary";
const wb2 = XLSX.read("1,2,3\n4,5,6", read_opts);
write_opts.type = "binary";
const out2 = XLSX.write(wb2, write_opts);

read_opts.type = "buffer";
const wb3 = XLSX.read(fs.readFileSync("sheetjs.xlsx"), read_opts);
write_opts.type = "base64";
const out3 = XLSX.write(wb3, write_opts);
write_opts.type = "array";
const out4 = XLSX.write(wb3, write_opts);

const ws1 = XLSX.utils.aoa_to_sheet([
    "SheetJS".split(""),
    [1,2,3,4,5,6,7],
    [2,3,4,5,6,7,8]
], {
開發者ID:CareerFairPlus,項目名稱:js-xlsx,代碼行數:31,代碼來源:doc.ts

示例5:

import * as XLSX from 'xlsx';

console.log(XLSX.version);

const bookType: string = "xlsb";
const fn: string = "sheetjsfbox." + bookType
const sn: string = "SheetJSFBox";
const aoa: any[][] = [ ["Sheet", "JS"], ["Fuse", "Box"], [72, 62] ];


var wb: XLSX.WorkBook = XLSX.utils.book_new();
var ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(aoa);
XLSX.utils.book_append_sheet(wb, ws, sn);

var payload: string = "";
var w2: XLSX.WorkBook;
if(typeof process != 'undefined' && process.versions && process.versions.node) {
	/* server */
	XLSX.writeFile(wb, fn);
	w2 = XLSX.readFile(fn)
} else {
	/* client */
	payload = XLSX.write(wb, {bookType: "xlsb", type:"binary"});
	w2 = XLSX.read(payload, {type:"binary"});
}

var s2: XLSX.WorkSheet = w2.Sheets[sn];
console.log(XLSX.utils.sheet_to_csv(s2));
開發者ID:CareerFairPlus,項目名稱:js-xlsx,代碼行數:28,代碼來源:sheetjs.ts


注:本文中的xlsx.read函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。