cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Milozebre74
Regular Visitor

Choose excel sheet to export

Good evening dear community,

 

I hope that you all are ok.
I have a question about Power PLC.
I have an excel file that has a lot of sheets. I would only like two sheets in a new file but I can't.
I found a solution by hiding the sheets but we always know them and for security reasons this should not be possible.
Is it possible to designate the sheets to export to an Excel file via Power automaton or if you have another solution ...
Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Yutao
Microsoft
Microsoft

Hello @Milozebre74 ,

 

Wondering if you can give the new "Run script" action of the Excel Online (Business) connector a try.

Yutao_0-1599195368385.png

 

This new action can run a script (Office Scripts) in Power Automate against a workbook. Office Scripts can do many tasks including deleting worksheets, which probably can solve the problem you mentioned here.

 

Here is a sample script that can delete all the worksheets in the workbook except for "Sheet 1" and "Sheet 2":

 

function main(workbook: ExcelScript.Workbook) {
  const sheetsToKeep = ["Sheet1", "Sheet2"];
  const allSheets = workbook.getWorksheets();
  allSheets.forEach(sheet => {
    if (!sheetsToKeep.includes(sheet.getName())) {
      sheet.delete();
    }
  });
}

 

 

 Here are a few links that might be helpful to learn about using Office Scripts with Power Automate:

 

Hope this helps!

Yutao

View solution in original post

1 REPLY 1
Yutao
Microsoft
Microsoft

Hello @Milozebre74 ,

 

Wondering if you can give the new "Run script" action of the Excel Online (Business) connector a try.

Yutao_0-1599195368385.png

 

This new action can run a script (Office Scripts) in Power Automate against a workbook. Office Scripts can do many tasks including deleting worksheets, which probably can solve the problem you mentioned here.

 

Here is a sample script that can delete all the worksheets in the workbook except for "Sheet 1" and "Sheet 2":

 

function main(workbook: ExcelScript.Workbook) {
  const sheetsToKeep = ["Sheet1", "Sheet2"];
  const allSheets = workbook.getWorksheets();
  allSheets.forEach(sheet => {
    if (!sheetsToKeep.includes(sheet.getName())) {
      sheet.delete();
    }
  });
}

 

 

 Here are a few links that might be helpful to learn about using Office Scripts with Power Automate:

 

Hope this helps!

Yutao

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!