Thep Excel

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

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

= Binary.Decompress(binary, compressionType)

By ThepExcel AI Agent
12 December 2025

Function Metrics


Popularity
4/10

Difficulty
5/10

Usefulness
5/10

Syntax & Arguments

= Binary.Decompress(binary, compressionType)

Argument Type Required Default Description
binary binary Yes ข้อมูลไบนารี่ที่ถูกบีบอัดแล้ว
compressionType number Yes ประเภทการบีบอัดที่ใช้ (Compression.GZip หรือ Compression.Deflate)

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 ที่ไม่ได้บีบอัด
Power Query Formula:

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

Result:

#binary({71, 0, 111, 0, 111, 0, 100, 0, 98, 0, 121, 0, 101, 0})

ยกเลิกการบีบอัด GZip ในโครงสร้าง let…in
let 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 ยกเลิกการบีบอัด แล้วส่งกลับข้อมูลต้นฉบับ
Power Query Formula:

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

Result:

binary ที่ไม่ได้บีบอัดแล้ว

ยกเลิกการบีบอัดจาก Web API Response
let Response = Json.Document( Web.Contents("https://api.example.com/data") ), CompressedBinary = Response[compressed_data], Decompressed = Binary.Decompress(Com…
ดึงข้อมูล binary ที่บีบอัดมาจาก API ยกเลิกการบีบอัด แล้วแปลง binary เป็น text ด้วย Binary.ToText
Power Query Formula:

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

Result:

ข้อความที่อ่านได้จากข้อมูลบีบอัด

ตรวจสอบประเภทการบีบอัดก่อนยกเลิก
let CompressedData = #binary({115, 103, 200, 7}), CompressionMethod = Compression.Deflate, Decompressed = try Binary.Decompress(CompressedData, CompressionMetho…
ใช้ try…otherwise เพื่อป้องกันข้อผิดพลาด ถ้าข้อมูลไม่ได้บีบอัดตรงกับประเภทที่ระบุ
Power Query Formula:

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

Result:

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

Additional Notes

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

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

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

Leave a Reply

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