question

bernardmwanza-0900 avatar image
0 Votes"
bernardmwanza-0900 asked AungZawMinThwin-9152 answered

How to load and read excel file hosted in sharepoint online using powershell

Hi all,

I'm working on a PowerShell script to read content in excel file hosted in SharePoint online in office 365.

My goal is retrieve content for cell B2 from the file.

My code so far,


     $Excel = New-Object -ComObject Excel.Application
     $Workbook = $Excel.Workbooks.Open("\\bernardcomms.sharepoint.com\sites\Test_Site\Documents\test_with_macro.xlsm")
     $Excel.Workbooks.CheckOut("\\bernardcomms.sharepoint.com\sites\Test_Site\Documents\test_with_macro.xlsm")
         
     # Get the first sheet in excel file 
     $workSheet = $Workbook.Sheets.Item(1)
     $WorkSheet.Name
    
     # Get value for cell B2
     $mailto = $workSheet.cells.Item(2, 2).Text
     $mailto.Text

On executing the script above, it just hangs. What am i doin wrong.



office-sharepoint-onlinewindows-server-powershell
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am currently looking into this issue and will give you an update as soon as possible.

Thank you for your understanding and support.

0 Votes 0 ·

Hi, any news?
Would like to achieve the same thing :)

Thanks,

Gabor

0 Votes 0 ·
mcpyassine avatar image
0 Votes"
mcpyassine answered

Hello,

Try
$mailto = $workSheet.cells.Item(2, 2)
or
$mailto = $workSheet.cells.Item(2, 2).Value

If the answer is helpful, please click "Accept Answer" and kindly upvote it.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AungZawMinThwin-9152 avatar image
0 Votes"
AungZawMinThwin-9152 answered

Please try one of below to open workbook.

 $WorkBook = $Excel.Workbooks.Open('https://bernardcomms.sharepoint.com/sites/Test_Site/Documents/test_with_macro.xlsm')

or

 $WorkBook = $Excel.Workbooks.Open('\\bernardcomms.sharepoint.com@SSL\DavWWWRoot\sites\Test_Site\Documents\test_with_macro.xlsm')



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.