Cách lấy link file excel nguồn cho Power query từ Onedrive, Google drive

Liên hệ QC

ptm0412

Bad Excel Member
Thành viên BQT
Administrator
Tham gia
4/11/07
Bài viết
13,813
Được thích
36,330
Donate (Momo)
Donate
Giới tính
Nam
Nghề nghiệp
Consultant
1. OneDrive:
Chọn file data, nhấn nút Embed
1652156129364.png

Nhấn nút Generate

1652156181209.png

Copy chuỗi embed:

1652156213801.png

Được chuỗi:
<iframe src="https://onedrive.live.com/embed?cid=B9C418BAD6EBE6BA&resid=B9C418BAD6EBE6BA%211887&authkey=AJG6yZZhYJsbyDk&em=2" width="402" height="346" frameborder="0" scrolling="no"></iframe>

Xóa đầu xóa đuôi, lấy từ https:// đến em=2, sửa embed thành download

"https:// onedrive.live.com/download?cid=B9C418BAD6EBE6BA&resid=B9C418BAD6EBE6BA%211887&authkey=AJG6yZZhYJsbyDk&em=2"

Dùng chuỗi này get data from web

1652156369270.png



2. Google drive
Bấm chuột phải vào file, nhấn Get link

1652156652104.png

Nhấn copy link
1652156693613.png

Ta được:

"https://docs.google.com/spreadsheets/d/1Xc_C3F3cAjYnB3WCWYZ8J0XpKVnMIPg4/edit?usp=sharing&ouid=104893641340913559968&rtpof=true&sd=true"

Sửa lại thành:
"https://docs.google.com/spreadsheets/d/1Xc_C3F3cAjYnB3WCWYZ8J0XpKVnMIPg4/export?format=xlsx"

Đưa vào get data from web
 
Lần chỉnh sửa cuối:
Đưa vào get data from web

Bác dùng cái hàm này xem thử.


PHP:
'# OneDrive link
Function ConvertUrlOD(sURL As String) As String
    ConvertUrlOD = VBA.Replace(sURL, "embed?", "download?")
End Function

'# GoogleDrive link
Function ConvertUrlGD(sURL As String) As String
    Dim prefixURL As String
    prefixURL = "https://docs.google.com/uc?export=download&id="
    ConvertUrlGD = VBA.Replace(sURL, "https://drive.google.com/file/d/", prefixURL)
    ConvertUrlGD = VBA.Replace(ConvertUrlGD, "/view?usp=sharing", "")
End Function
 
Bác dùng cái hàm này xem thử.


PHP:
'# OneDrive link
Function ConvertUrlOD(sURL As String) As String
    ConvertUrlOD = VBA.Replace(sURL, "embed?", "download?")
End Function

'# GoogleDrive link
Function ConvertUrlGD(sURL As String) As String
    Dim prefixURL As String
    prefixURL = "https://docs.google.com/uc?export=download&id="
    ConvertUrlGD = VBA.Replace(sURL, "https://drive.google.com/file/d/", prefixURL)
    ConvertUrlGD = VBA.Replace(ConvertUrlGD, "/view?usp=sharing", "")
End Function
Tôi đang dùng thuần PQ, không có VBA. Và hình như bạn nhầm GGDrive export và view
 
Cái quan trọng nhất phải lưu ý, đó là anh cần thiết lập chia sẻ công khai thì mới truy cập vào tập tin để lấy dữ liệu.

1652158399256.png
 
Tôi đang dùng thuần PQ, không có VBA. Và hình như bạn nhầm GGDrive export và view
Cách dưới đây là kết hợp VBA chuyển đổi chuỗi URL lưu xuống Cell và PQ tham chiếu tới nó. :)
Đặt Name cho Cell chứa link URL là URLString.

TCCpSqv.png


Mã:
let
    GetURL=Excel.CurrentWorkbook(){[Name="URLString"]}[Content][Column1]{0},
    Source = Excel.Workbook(Web.Contents(GetURL),null,true),
    Navigation = Source{[Item="Data",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Navigation,[PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Stt", Int64.Type}, {"Ngày", type date}, {"Bộ phận", type text}, {"Họ và Tên", type text}, {"Doanh số", Int64.Type}})
in
    #"Changed Type"
 
1. OneDrive:
Chọn file data, nhấn nút Embed
View attachment 275705

Nhấn nút Generate

View attachment 275706

Copy chuỗi embed:

View attachment 275707

Được chuỗi:
<iframe src="https://onedrive.live.com/embed?cid=B9C418BAD6EBE6BA&resid=B9C418BAD6EBE6BA%211887&authkey=AJG6yZZhYJsbyDk&em=2" width="402" height="346" frameborder="0" scrolling="no"></iframe>

Xóa đầu xóa đuôi, lấy từ https:// đến em=2, sửa embed thành download

"https:// onedrive.live.com/download?cid=B9C418BAD6EBE6BA&resid=B9C418BAD6EBE6BA%211887&authkey=AJG6yZZhYJsbyDk&em=2"

Dùng chuỗi này get data from web

View attachment 275708



2. Google drive
Bấm chuột phải vào file, nhấn Get link

View attachment 275711

Nhấn copy link
View attachment 275712

Ta được:

"https://docs.google.com/spreadsheets/d/1Xc_C3F3cAjYnB3WCWYZ8J0XpKVnMIPg4/edit?usp=sharing&ouid=104893641340913559968&rtpof=true&sd=true"

Sửa lại thành:
"https://docs.google.com/spreadsheets/d/1Xc_C3F3cAjYnB3WCWYZ8J0XpKVnMIPg4/export?format=xlsx"

Đưa vào get data from web
Em Vân muốn hỏi Thầy chút là nếu ở Onedriver có 100 File thì có cách nào dùng load được cả Folder vào không ạ ?

Nếu tạo 100 File thì sẽ có thể bị nhầm lẫn giữa các File ạ

Em Vân cảm ơn Thầy ạ
 
Web KT
Back
Top Bottom