Thep Excel

Binary.Decompressยกเลิกการบีบอัดข้อมูลไบนารี่

Binary.Decompress ยกเลิกการบีบอัดข้อมูลไบนารี่ที่ถูกบีบอัดด้วย GZip หรือ Deflate กลับเป็นข้อมูลต้นฉบับ

fx
= Binary.Decompress(binary, compressionType)

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

อัปเดต 12 December 2025

Syntax & Arguments

อาร์กิวเมนต์ ชนิด คำอธิบาย
binary binary ข้อมูลไบนารี่ที่ถูกบีบอัดแล้ว
compressionType number ประเภทการบีบอัดที่ใช้ (Compression.GZip หรือ Compression.Deflate)

Additional Notes

Binary.Decompress ยกเลิกการบีบอัดข้อมูลไบนารี่โดยรับข้อมูลที่ถูกบีบอัดแล้วและชนิดของการบีบอัดเป็น parameter จากนั้นส่งกลับข้อมูลดั้งเดิมแบบ binary ต่างจาก Binary.Compress ที่ทำให้เล็กลงโดยบีบอัด

ที่เจ๋งคือสามารถทำให้ข้อมูลอัด GZip หรือ Deflate กลับมาใช้ได้เหมือนเดิม เหมาะสำหรับการแตกไฟล์ที่ดาวน์โหลดมา หรือเวลาดึงข้อมูลจาก API ที่มีการบีบอัด

ส่วนตัวผมใช้ฟังก์ชันนี้บ่อยมากเวลาต้องทำงานกับไฟล์ ZIP หรือข้อมูลที่บีบอัดมาจาก server เพราะต้องแตกออกก่อนถึงจะใช้ได้

Examples

ยกเลิกการบีบอัด Deflate แบบง่ายๆBinary.Decompress( #binary({115, 103, 200, 7, 194, 20, 134, 36, 134, 74, 134, 84, 6, 0}), Compression.Deflate )

ยกเลิกการบีบอัด Deflate จาก binary ที่มี 14 bytes กลับเป็นข้อมูลต้นฉบับ ผลลัพธ์เป็น binary ที่ไม่ได้บีบอัด

fx
= Binary.Decompress(
#binary({115, 103, 200, 7, 194, 20, 134, 36, 134, 74, 134, 84, 6, 0}),
Compression.Deflate
)

ผลลัพธ์#binary({71, 0, 111, 0, 111, 0, 100, 0, 98, 0, 121, 0, 101, 0})
ยกเลิกการบีบอัด GZip ในโครงสร้าง let…inlet CompressedData = #binary({31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 75, 44, 0, 0}), Decompressed = Binary.Decompress(CompressedData, Compression.GZip) in Decompres…

บันทึก binary ที่บีบอัดด้วย GZip ในตัวแปร จากนั้นใช้ Binary.Decompress ยกเลิกการบีบอัด แล้วส่งกลับข้อมูลต้นฉบับ

fx
let
CompressedData = #binary({31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 75, 44, 0, 0}),
Decompressed = Binary.Decompress(CompressedData, Compression.GZip)
in
Decompressed

ผลลัพธ์binary ที่ไม่ได้บีบอัดแล้ว
ยกเลิกการบีบอัดจาก Web API Responselet Response = Json.Document( Web.Contents("https://api.example.com/data") ), CompressedBinary = Response[compressed_data], Decompressed = Binary.Decompress(Com…

ดึงข้อมูล binary ที่บีบอัดมาจาก API ยกเลิกการบีบอัด แล้วแปลง binary เป็น text ด้วย Binary.ToText

fx
let
Response = Json.Document(
Web.Contents("https://api.example.com/data")
),
CompressedBinary = Response[compressed_data],
Decompressed = Binary.Decompress(CompressedBinary, Compression.Deflate),
Text = Binary.ToText(Decompressed, BinaryEncoding.Utf8)
in
Text

ผลลัพธ์ข้อความที่อ่านได้จากข้อมูลบีบอัด
ตรวจสอบประเภทการบีบอัดก่อนยกเลิกlet CompressedData = #binary({115, 103, 200, 7}), CompressionMethod = Compression.Deflate, Decompressed = try Binary.Decompress(CompressedData, CompressionMetho…

ใช้ try…otherwise เพื่อป้องกันข้อผิดพลาด ถ้าข้อมูลไม่ได้บีบอัดตรงกับประเภทที่ระบุ

fx
let
CompressedData = #binary({115, 103, 200, 7}),
CompressionMethod = Compression.Deflate,
Decompressed = try Binary.Decompress(CompressedData, CompressionMethod)
otherwise null
in
Decompressed

ผลลัพธ์binary ที่ไม่ได้บีบอัด หรือ null ถ้าเกิดข้อผิดพลาด

FAQs

ต่างจาก Binary.Compress อย่างไร?+

Binary.Compress บีบอัดข้อมูลให้เล็กลง ส่วน Binary.Decompress ยกเลิกการบีบอัดให้กลับมาใช้ได้ เป็นฟังก์ชันตรงข้ามกัน ผมแนะนำให้ใช้ Compress เวลาต้องการส่งข้อมูลขนาดใหญ่ ใช้ Decompress เวลาต้องการแตกไฟล์ที่ได้รับมา

ต้องใช้ Compression.GZip หรือ Compression.Deflate อันไหน?+

มันขึ้นอยู่กับว่าข้อมูลถูกบีบอัดด้วยวิธีไหนมา ถ้าบีบอัดด้วย GZip ต้องใช้ Compression.GZip โดยการผิดพลาดจะถูก Error อย่างชัดเจน ผมแนะนำให้ดู file header หรือขอเอกสารจากแหล่งข้อมูล

ถ้าข้อมูลไม่ได้บีบอัดหรือบีบอัดแบบผิดจะเกิดอะไร?+

จะ Error ออกมา ผมแนะนำให้ใช้ try…otherwise ครอบไว้ เพื่อไม่ให้ query หยุดชะงัก

สามารถใช้กับข้อมูลขนาดใหญ่ได้หรือเปล่า?+

ได้ แต่ Power Query ต้องมีหน่วยความจำพอ ผมเคยใช้กับไฟล์ที่บีบอัด 100MB ไม่มีปัญหา แต่ต้องแน่ใจว่า refresh ไม่ timeout

Resources & Related

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

ฟังก์ชันนี้Binary.DecompressBinary functions
Binary functions (4)
Binary.Compress

Binary.Compress บีบอัดข้อมูลไบนารี่โดยใช้อัลกอริทึมการบีบอัด (เช่น GZIP)

Binary.FromText

Binary.FromText แปลงสตริงข้อความเป็นข้อมูลไบนารี่ที่สามารถใช้กับการเข้ารหัส Base64 หรือ Hex ได้

Binary.ToList

Binary.ToList แปลงข้อมูลไบนารี่เป็นรายการของตัวเลข (bytes)

Binary.ToText

Binary.ToText แปลงข้อมูลไบนารี่เป็นข้อความโดยระบุวิธีการเข้ารหัส ใช้ได้ทั้ง Base64 และ Hex

enumerations (1)
Compression.Type

Compression.Type เป็น enumeration ใน Power Query ที่ช่วยกำหนดประเภทการบีบอัดข้อมูล เช่น GZip, Deflate, Snappy, Brotli, LZ4, Zstandard เมื่อทำงานกับ Binary.Compress หรือ Binary.Decompress

Accessing data functions (1)
Json.Document

Json.Document ใช้สำหรับแปลง JSON text หรือ binary data ให้เป็น Power Query record ทำให้คุณสามารถเข้าถึง field แต่ละตัวได้อย่างง่ายดาย

Comments

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