SharePoint.Files ดึงตารางข้อมูลของเอกสารและโฟลเดอร์จาก SharePoint รวมถึงโฟลเดอร์ย่อยทั้งหมด คืนค่าเป็นตารางที่มีข้อมูลและลิงก์เข้าถึงไฟล์
=SharePoint.Files(url as text, optional options as nullable record) as table
=SharePoint.Files(url as text, optional options as nullable record) as table
| Argument | Type | Required | Default | Description |
|---|---|---|---|---|
| url | text | Yes | URL ของไซต์ SharePoint ที่ต้องการดึงข้อมูลไฟล์ เช่น https://yourcompany.sharepoint.com/sites/ProjectName | |
| options | record (nullable) | Optional | null | ตัวเลือกเพิ่มเติมสำหรับการกำหนดค่า ได้แก่ ApiVersion (ระบุเวอร์ชัน API: 14, 15, หรือ “Auto”) |
let SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject", Files = SharePoint.Files(SharePointURL) in Fileslet
SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject",
Files = SharePoint.Files(SharePointURL)
in
Files
ตารางแสดงไฟล์และโฟลเดอร์ทั้งหมดจากไซต์ SharePoint รวม Columns เช่น Name, Date accessed, Date modified, Size และ Content
let SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject", AllFiles = SharePoint.Files(SharePointURL), ExcelOnly = Table.SelectRows(AllFiles, eac…let
SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject",
AllFiles = SharePoint.Files(SharePointURL),
ExcelOnly = Table.SelectRows(AllFiles, each Text.EndsWith([Name], ".xlsx") or Text.EndsWith([Name], ".xls"))
in
ExcelOnly
ตารางแสดงเฉพาะไฟล์ Excel ที่นามสกุลเป็น .xlsx หรือ .xls เท่านั้น
let SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject", AllFiles = SharePoint.Files(SharePointURL), RecentFiles = Table.SelectRows( AllFiles,…let
SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject",
AllFiles = SharePoint.Files(SharePointURL),
RecentFiles = Table.SelectRows(
AllFiles,
each [Date modified] >= Date.From(Date.AddDays(DateTime.FixedLocalNow(), -7))
)
in
RecentFiles
ตารางแสดงเฉพาะไฟล์ที่แก้ไขในช่วง 7 วันที่ผ่านมา
let SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject", Options = [ApiVersion = "Auto"], Files = SharePoint.Files(SharePointURL, Options) in F…let
SharePointURL = "https://yourcompany.sharepoint.com/sites/MyProject",
Options = [ApiVersion = "Auto"],
Files = SharePoint.Files(SharePointURL, Options)
in
Files
ตารางไฟล์จาก SharePoint โดยระบบจะเลือก API version ที่เหมาะสมโดยอัตโนมัติ
ดึงทั้งไฟล์และโฟลเดอร์ครับ ผลลัพธ์จะรวมทั้งสองอย่างอยู่ในตารางเดียวกัน ถ้าต้องการแยกออก ให้ใช้ Table.SelectRows เพื่อกรองตามคอลัมน์ Attributes หรือตรวจสอบสิ่งอื่นๆ ที่บ่งบอกว่าเป็นไฟล์หรือโฟลเดอร์
ต้องระบุ ApiVersion ให้เป็น 15 ขึ้นไป ส่วนตัวผมแนะนำให้ใช้ “Auto” เสมอครับ เพราะมันจะตรวจสอบและเลือกเอง แต่ถ้าระบบ Auto ไม่ได้ลองเปลี่ยนเป็น 15 ดูนะครับ
ใช่ครับ ดึงแบบ Recursive อัตโนมัติ ถ้าไซต์มีโฟลเดอร์ซ้อนลึก มันจะไปหาหมดให้เองเลย ไม่ต้องสร้าง Loop เอง 😎
SharePoint.Files เป็นฟังก์ชันสำหรับดึงข้อมูลเอกสารจากไซต์ SharePoint ได้ทั้งจากโฟลเดอร์หลักและโฟลเดอร์ย่อยอัตโนมัติ โดยจะคืนค่าเป็นตารางที่มีรายละเอียดของแต่ละไฟล์
ที่เจ๋งคือมันดึงข้อมูลแบบ Recursive ได้ เลยไม่ต้องเขียน Loop เองเพื่อไปจัดกับโฟลเดอร์ซ้อนลึก แถมยังให้ลิงก์เข้าถึงไฟล์ได้เลยภายในผลลัพธ์
ส่วนตัวผมชอบใช้ฟังก์ชันนี้คู่กับ Table.SelectRows เพื่อกรองไฟล์ที่ต้องการเท่านั้น เช่นกรองเฉพาะไฟล์ Excel หรือไฟล์ที่สร้างขึ้นในวันนี้ ทำให้ประมวลผลได้เร็วขึ้นมาก 😎