Forum

Is there any simila...
 
Notifications
Clear all

Is there any similar M code for Excel.CurrentWorkbook( ) for bring in external xlsx to a blank worksheet

6 Posts
2 Users
0 Reactions
292 Views
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi,

I was amazed by the M code Excel.CurrentWorkbook( ) that allow us to append several worksheets easily,  without using Append query in PQ editor

Is there any equivalent M code for bringing in worksheets from various sources ( D drive,  server drive) into Power Query, without bringing in the physical tables ( or minimally) into one single query just like Excel.CurrentWorkbook( )

for e.g.

I open a new workbook,  open a blank query at formula bar key in equivalent M code to bring in PC_1 ad PC_2 tables from the attach

Thank you !

 
Posted : 22/11/2019 10:41 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Chris,

Not sure what you want.

D Drive I guess is a local drive?

You can use File.Contents(FilePath) , this will return file data in binary format, then you can add a new column with the formula =Excel.Workbook([Content]) to extract data from the file.

 
Posted : 22/11/2019 2:24 pm
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi Catalin,

I try to explain,, 

in my attached example, because the source file is in the excel itself,  I can use =Excel.CurrentWorkbook( )   in the blank query and that it

what if I open up a blank excel workbook,   open a blank query,  you mean I can use =File.Contents( d:tempfile.xlsx) to import in ?

 
Posted : 23/11/2019 1:09 am
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi Catalin,  basically I want to just issue a M code that will consolidate all the worksheets like what Excel.CurrentWorkbook( )  did,   i.e.  instead of import physically to PQ and then use Append query to combine them

Is this possible ?

 
Posted : 23/11/2019 1:24 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Chris,

Attached is an example, you can use that, or start with a blank query with this formula:

= Excel.Workbook(File.Contents("C:UsersCatalinDesktopNew folderSourceTable.xlsx"), null, true)

This will give you the list of sheets in that workbook, you can select the ones you want and expand the data table.

As mentioned, I only used File.Contents()  and Excel.Workbook() to extract data from the file.

Nothing is stopping you from trying, I think trying things is the best way to go, even if it fails sometimes.

 
Posted : 23/11/2019 6:07 am
(@bluesky63)
Posts: 162
Estimable Member
Topic starter
 

Hi Catalin,  perfect !  this is exactly what I am looking for,  however some users still like to import all the tabs into PQ and append it

so I thought by just writing this short code ( thanks to you !!)

= Excel.Workbook(File.Contents("C:UsersJO_HOMEDownloadstempExcelCurrentWorkbook.xlsx"), null, true)

it is clean,  light and display what I want,  the master combined dataset

 

Chris Yap

 
Posted : 23/11/2019 8:47 am
Share: