web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get Last Line with Off...
Power Automate
Unanswered

Get Last Line with Office Scripts

(0) ShareShare
ReportReport
Posted on by 67

I have a .xlsx with a lot of rows of information, I wonder how can I get the last line of this document? 

 

I'm supposed to be adding more lines to the end of the archive, every month. There is a sample of the script I'm working on:

 

function main(workbook: ExcelScript.Workbook) {
 let selectedSheet = workbook.getWorksheet("sheet");
 return JSON.stringify(selectedSheet.getRange());
}

 

Also tried with: 

return JSON.stringify(selectedSheet.getRange().getVisibleView().getValues());
 
But I'm getting the error:
 
Converting circular structure to JSON
--> starting at object with constructor 't'
| property 'm_trackedObjects' -> object with constructor 'e'
--- property 'm_context' closes the circle
clientRequestId: 986aa897-d022-43a5-b32e-672524deb8c8
 
Maybe you can help me with this, thanks!

 

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @victor_lion 

     

    You could probably get away without using Office Scripts and do something like https://www.exceltip.com/lookup-formulas/find-the-last-row-of-data-in-excel.html 

  • victor_lion Profile Picture
    67 on at

    Hi, I'm looking to a function like .getUsedRange(), as I am no trying to add more content to the file. 

  • Yutao Huang Profile Picture
    Microsoft Employee on at

    Hey @victor_lion ,

     

    Wondering if you have tried Range.getSurroundingRegion( ) . I think that should work as long as there are no completely blank rows or blank columns within the range.

     

    https://docs.microsoft.com/en-us/javascript/api/office-scripts/excelscript/excelscript.range?view=office-scripts#getSurroundingRegion__

     

    -Yutao

  • victor_lion Profile Picture
    67 on at

    Thank you @Yutao I've solved this problem using the following script:

     let columnValues = selectedSheet.getUsedRange(true).getColumn(column).getValues();
     return columnValues;

     

    And by this I get an array, so by this I know the length of the file, and can get the last line.

  • Verified answer
    Yutao Huang Profile Picture
    Microsoft Employee on at

    @victor_lion - it's great to hear you've found the solution! Wondering if you could also try selectedSheet.getUsedRange(true).getRowCount(), which might be a bit more efficient.

  • victor_lion Profile Picture
    67 on at

    Yes @Yutao it works! Thanks! 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard