'How should I insert one more column in excel in javascript?
I have to put file sizes(need to capture from UI) near to file name(contained in excel) but was finding it difficult to insert such entry and so I created another sheet and class named FileProperties with filePath and fileSize. Then I had put the entries as JSON into new worksheet, then I want to delete the old sheet containing just the file names and want to rename the existing sheet so that it appears same. But when I used rename() and delete() on worksheet level I got an error and the work is more tedious then if I can write the file sizes near to file name in the old sheet.
FileProperties class
export class FileProperties {
filePath;
fileSize;
}
Below are the initialization and initially InputSheet is empty and Input_Data is holding File paths under File Path heading
inputWorksheet = workbook.Sheets.InputSheet;
oldInputSheet = workbook.Sheets.Input_Data;
const temp = XLSXReader.utils.sheet_to_json(oldInputSheet);
temp.forEach((res) => {
data.push(res);
});
Below is the code which I was trying to get the entries in new sheet which worked successfully.
allDataEle = await page.waitForSelector (
"locator passed here"
);
fileSize = await page.evaluate((el) => el.textContent.trim(), allDataEle);
//data is an object which refers to row of old sheet
fileProperties.filePath = data[i]['File Path'];
fileProperties.fileSize = fileSize;
fileProp = [fileProperties];
cell = 'A' + (i+2);
//inputWorksheet is referring to new sheet name
XLSXReader.utils.sheet_add_json(inputWorksheet, fileProp, {
skipHeader: true,
origin: cell
});
XLSXReader.writeFile(workbook, excelSheetName.xlsx');
I am getting proper data but want to write the file sizes in the old sheet and not getting another sheet for this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
