---
title: Text.ToBinary – แปลง Text เป็น Binary
url: https://www.thepexcel.com/functions/power-query/text-functions/text-tobinary/
type: function-explainer
program: Power Query
syntax: "Text.ToBinary(text as nullable text, optional encoding as nullable number, optional includeByteOrderMark as nullable logical) as nullable binary"
date: 2025-12-04
updated: 2025-12-17
scores:
  popularity: 5
  difficulty: 3
  usefulness: 5
---

# Text.ToBinary – แปลง Text เป็น Binary

> แปลงข้อความเป็นค่า Binary

## คำอธิบาย

Text.ToBinary ใช้สำหรับแปลงข้อความเป็นค่า Binary โดยใช้การเข้ารหัส UTF-8 เป็นค่าเริ่มต้น รองรับการเข้ารหัส UTF-16 และ ASCII

## Syntax

```excel
Text.ToBinary(text as nullable text, optional encoding as nullable number, optional includeByteOrderMark as nullable logical) as nullable binary
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | nullable text |  | ข้อความที่ต้องการแปลง |
| encoding | No | nullable number | BinaryEncoding.Utf8 | ประเภทการเข้ารหัส |
| includeByteOrderMark | No | nullable logical | false | เพิ่ม Byte Order Mark หรือไม่ |

## เคสการใช้งาน

### บันทึกข้อความลงไฟล์ Binary

บันทึกข้อความลงไฟล์ Binary

### ส่งข้อมูลแบบ Binary ไป API

ส่งข้อมูลแบบ Binary ไป API

### เข้ารหัส Binary สำหรับการส่งข้อมูล

เข้ารหัส Binary สำหรับการส่งข้อมูล

## ตัวอย่าง

### 1. แปลง Text เป็น Binary

```excel
Text.ToBinary("Hello")
```

**ผลลัพธ์:** `#binary({72, 101, 108, 108, 111})`

แปลง 'Hello' เป็น bytes

### 2. Round-trip conversion

```excel
Text.FromBinary(Text.ToBinary("Test"))
```

**ผลลัพธ์:** `Test`

แปลง Text → Binary → Text

### 3. เข้ารหัส Base64

```excel
Binary.ToText(Text.ToBinary("Hello"), BinaryEncoding.Base64)
```

**ผลลัพธ์:** `SGVsbG8="`

แปลง Text เป็น Binary แล้วเข้ารหัส Base64

## ฟังก์ชันที่เกี่ยวข้อง

- [Text.FromBinary – แปลง Binary เป็น Text](https://www.thepexcel.com/functions/power-query/text-functions/text-frombinary/)
- [Text.From – แปลงค่าเป็นข้อความ](https://www.thepexcel.com/functions/power-query/text-functions/text-from/)
- [Binary.ToText – แปลงไบนารี่เป็นข้อความ](https://www.thepexcel.com/functions/power-query/binary-functions/binary-totext/)

## แหล่งข้อมูลเพิ่มเติม

- [Microsoft Learn: Text.ToBinary](https://learn.microsoft.com/en-us/powerquery-m/text-tobinary) _(Official Documentation)_

---

_Source: [https://www.thepexcel.com/functions/power-query/text-functions/text-tobinary/](https://www.thepexcel.com/functions/power-query/text-functions/text-tobinary/)_
