Forum Discussion
Convert CSV to Excel Office Script
Perhaps you mean this Convert CSV files to Excel workbooks - Office Scripts | Microsoft Learn template in which sheet name is defined explicitly ( as "Sheet1"). Be sure all csv files have sheet with such name.
As variant most probably script could be modified to select the sheet not by name but by position, e.g. first sheet in the file.
- aflesnerApr 29, 2023Copper Contributor
I think that selecting the sheet not by the name "Sheet1" but by position would fix this. How would that code be written?
- peiyezhuApr 29, 2023Bronze Contributorconvert an Excel sheet to csv?
or Csv 2 sheet?- SergeiBaklanMay 01, 2023Diamond Contributor
The idea of this template is to convert set of csv files into Excel ones with help of Power Automate and using Excel on web.
- SergeiBaklanApr 29, 2023Diamond Contributor
Instead of
let sheet = workbook.getWorksheet("Sheet1");you may use
const sheet = workbook.getWorksheets()[0]to return very first sheet (numbering starts from zero). You may check the sheet name by
console.log(sheet.getName())Just in case, equivalent syntax is
let sheet = workbook.getWorksheets()[0];- aflesnerMay 01, 2023Copper Contributor
SergeiBaklan I replaced you suggestion now I am getting a different error? I am getting an error with line 8 csv = csv.replace("/\r/g, """);
Error is Line 8 Cannot read properties of undefined (reading 'replace')