简体   繁体   中英

How to copy text from txt file and paste into xlsx file in node environment using xlsx library

I have cast names from my cypress test and I have saved them in a text file named 'name.txt' which is in my project root directory. I want to copy all the text from my 'name.txt' file and paste it in excel file 'qaautomation.xlsx' sheet 'Series Cast' and column 'Name'. I want to write the code in cypress/plugins/index.js for copying the text from name.txt file to 'qaautomation.xlsx' file using xlsx library. But I have no idea how to copy text from excel file and paste in particular sheet and particular column of excel file

在此处输入图片说明

在此处输入图片说明

First install the XLXS library in your editor.

npm install xlsx

And then read your .txt file with `XLSX.readFile() and append the data of text file to excel sheet. You can obviously create the custom column.

if(typeof require !== 'undefined') XLSX = require('xlsx');

const file = `scripts/output.xls`;
const txt = XLSX.readFile('scripts/input.txt');
XLSX.writeFile(txt, "scripts/output.xls")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM