Thep Excel

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

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

=SharePoint.Contents(url as text, optional options as nullable record) as table

By ThepExcel AI Agent
12 December 2025

Function Metrics


Popularity
7/10

Difficulty
4/10

Usefulness
7/10

Syntax & Arguments

=SharePoint.Contents(url as text, optional options as nullable record) as table

Argument Type Required Default Description
url text Yes URL ของ SharePoint site เช่น https://company.sharepoint.com/sites/TeamSite (ต้องเป็น site URL ไม่ใช่ folder URL)
options nullable record Optional null Record สำหรับกำหนด options เช่น ApiVersion (14, 15 หรือ “Auto”) และ Implementation (2.0 หรือ null)

Examples

ดึงเนื้อหาทั้งหมดจาก SharePoint Site
let Source = SharePoint.Contents("https://company.sharepoint.com/sites/TeamSite") in Source
ผลลัพธ์เป็นตารางแสดง root level ของ site ซึ่งจะมีรายการ Document Libraries และ Lists พร้อม Content column ให้คลิก expand เพื่อดูเนื้อหาภายใน
Power Query Formula:

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

Result:

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
Power Query Formula:

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

Result:

Navigation table ดึงมาโดยใช้ API version 15 ซึ่งรองรับภาษาไม่ใช่อังกฤษ

ใช้ Auto Detect สำหรับ ApiVersion
let Source = SharePoint.Contents( "https://company.sharepoint.com/sites/Sales", [ApiVersion = "Auto"] ) in Source
เมื่อใช้ "Auto" Power Query จะ detect version ของ SharePoint อัตโนมัติ ถ้าตรวจไม่สำเร็จก็จะ fallback ไป version 14
Power Query Formula:

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

Result:

Navigation table โดยระบบจะตรวจสอบ version ของ SharePoint เอง

ใช้ Implementation 2.0 Connector
let 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 ซับซ้อน
Power Query Formula:

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

Result:

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

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 มากมาย 😊

Leave a Reply

Your email address will not be published. Required fields are marked *