Thep Excel

SharePoint.Contentsดึงเนื้อหาจาก SharePoint Site เป็น Navigation Table

SharePoint.Contents ดึงรายการโฟลเดอร์และไฟล์ทั้งหมดจาก SharePoint site เป็น navigation table ที่สามารถ drill down ไปยัง Document Libraries และ Lists ต่างๆ ได้

fx
=SharePoint.Contents(url, [options]) as table

ความนิยม7/10
ความยาก4/10
ประโยชน์7/10

อัปเดต 12 December 2025

Syntax & Arguments

อาร์กิวเมนต์ ชนิด ค่าเริ่มต้น คำอธิบาย
url text URL ของ SharePoint site เช่น https://company.sharepoint.com/sites/TeamSite (ต้องเป็น site URL ไม่ใช่ folder URL)
[options]ไม่บังคับ nullable record null Record สำหรับกำหนด options เช่น ApiVersion (14, 15 หรือ “Auto”) และ Implementation (2.0 หรือ null)

[ ] = อาร์กิวเมนต์ที่ไม่บังคับ

Additional Notes

SharePoint.Contents เป็นฟังก์ชันสำหรับเชื่อมต่อกับ SharePoint site และดึงเนื้อหาทั้งหมดออกมาเป็น navigation table

ที่เจ๋งคือผลลัพธ์จะเป็นตารางแบบ hierarchical ซึ่งมี Content column เป็น link ที่สามารถคลิกเข้าไปยังเนื้อหาหนึ่งชั้นลึกได้ ทำให้เราสามารถสำรวจโครงสร้าง site ได้อย่างสะดวก

ส่วนตัวผมใช้ฟังก์ชันนี้เวลาต้องการดูภาพรวมของ site ว่ามี Document Library อะไรบ้าง แล้วค่อย drill down เข้าไปที่ library ที่ต้องการ ถ้าต้องการดึงไฟล์จาก folder เฉพาะโดยตรง ก็ใช้ SharePoint.Files ที่จะให้ flat list ไม่ต้องคลิก expand มากมาย 😊

Examples

ดึงเนื้อหาทั้งหมดจาก SharePoint Sitelet Source = SharePoint.Contents("https://company.sharepoint.com/sites/TeamSite") in Source

ผลลัพธ์เป็นตารางแสดง root level ของ site ซึ่งจะมีรายการ Document Libraries และ Lists พร้อม Content column ให้คลิก expand เพื่อดูเนื้อหาภายใน

fx
let
Source = SharePoint.Contents("https://company.sharepoint.com/sites/TeamSite")
in
Source

ผลลัพธ์Navigation table ที่มี Document Libraries และ Lists ต่างๆ ของ site
ใช้ ApiVersion 15 สำหรับ SharePoint ภาษาไทยlet Source = SharePoint.Contents( "https://company.sharepoint.com/sites/ThaiTeam", [ApiVersion = 15] ) in Source

SharePoint site ที่ใช้ภาษาอื่นนอกจากอังกฤษ เช่น ไทย จีน หรือญี่ปุ่น จำเป็นต้องใช้ ApiVersion 15 ขึ้นไป เพราะ version 14 อาจมีปัญหา encoding

fx
let
Source = SharePoint.Contents(
"https://company.sharepoint.com/sites/ThaiTeam",
[ApiVersion = 15]
)
in
Source

ผลลัพธ์Navigation table ดึงมาโดยใช้ API version 15 ซึ่งรองรับภาษาไม่ใช่อังกฤษ
ใช้ Auto Detect สำหรับ ApiVersionlet Source = SharePoint.Contents( "https://company.sharepoint.com/sites/Sales", [ApiVersion = "Auto"] ) in Source

เมื่อใช้ "Auto" Power Query จะ detect version ของ SharePoint อัตโนมัติ ถ้าตรวจไม่สำเร็จก็จะ fallback ไป version 14

fx
let
Source = SharePoint.Contents(
"https://company.sharepoint.com/sites/Sales",
[ApiVersion = "Auto"]
)
in
Source

ผลลัพธ์Navigation table โดยระบบจะตรวจสอบ version ของ SharePoint เอง
ใช้ Implementation 2.0 Connectorlet Source = SharePoint.Contents( "https://company.sharepoint.com/sites/HR", [ApiVersion = 15, Implementation = 2.0] ) in Source

Implementation 2.0 มี API ใหม่และ usability ดีขึ้น แต่มีข้อจำกัดเรื่อง join limit สูงสุด 12 operations ต้องระวังถ้า query ซับซ้อน

fx
let
Source = SharePoint.Contents(
"https://company.sharepoint.com/sites/HR",
[ApiVersion = 15, Implementation = 2.0]
)
in
Source

ผลลัพธ์Navigation table โดยใช้ connector version 2.0 ที่มี API ปรับปรุง

FAQs

SharePoint.Contents ต่างจาก SharePoint.Files อย่างไร?+

SharePoint.Contents ดึง navigation table ของทั้ง site ต้อง drill down ไปหา Document Library แต่ละชั้น ส่วน SharePoint.Files ดึงเฉพาะไฟล์จาก Document Library ที่ระบุโดยตรง ถ้าต้องการดึงไฟล์โดยตรงใช้ SharePoint.Files จะตรงประเด็นกว่า

ต้องใช้ ApiVersion 15 เสมอหรือ?+

ถ้า SharePoint site ใช้ภาษาอังกฤษ version 14 ก็พอ แต่ถ้าใช้ภาษาอื่นต้องใช้ 15 ขึ้นไป ผมแนะนำใส่ [ApiVersion = 15] เสมอเพื่อความปลอดภัย

เกิด error 401 Unauthorized ต้องทำอย่างไร?+

Error นี้เกิดจากไม่มีสิทธิ์เข้าถึง SharePoint site ให้ไปที่ Data Source Settings แล้ว Clear Permissions แล้ว sign in ใหม่ หรือติดต่อ admin เพื่อขอสิทธิ์

Resources & Related

ฟังก์ชันที่ผู้เขียนโยงไว้กับ SharePoint.Contents จัดกลุ่มตามหมวด · ชี้ที่ชื่อใดชื่อหนึ่ง แล้วฟังก์ชันที่ใช้คู่กันจะมีจุดทอง

ฟังก์ชันนี้SharePoint.ContentsAccessing data functions
Accessing data functions (1)
SharePoint.Tables

SharePoint.Tables เป็นฟังก์ชันสำหรับดึงข้อมูลทั้งหมดจาก SharePoint List มา Power Query โดยคืนค่าตารางที่มีแถวสำหรับแต่ละรายการใน List พร้อมกับจัดการการเชื่อมต่อและการรับรองตัวตนอัตโนมัติ

Comments

อีเมลของคุณจะไม่ถูกเผยแพร่