ไม่มีการติดตั้ง Excel บนเครื่องท้องถิ่น ไม่มีเซิร์ฟเวอร์แปลงไฟล์ที่ต้องดูแล เปลี่ยน XLSX → PDF, Excel → CSV/JSON/images/HTML ให้เป็นการเรียก REST ธรรมดา — และให้ “ตัวแปลงสเปรดชีตบนคลาวด์” ตัวแรกของคุณทำงานได้ภายในประมาณสามนาที

“Convert that spreadsheet to a different format” เป็นหนึ่งในความต้องการที่พบบ่อยที่สุดในงานพัฒนาแต่ละวัน:

  • ทีมการเงินและกฎหมายต้องการรายงาน PDF อ่านอย่างเดียว, ป้องกันการดัดแปลง PDF แทนไฟล์ .xlsx ที่ใครก็แก้ไขได้;
  • ทีมข้อมูลต้องการดึงข้อมูลตารางเข้าสู่ระบบ downstream ในรูปแบบ CSV / JSON;
  • แอปเว็บและมือถือต้องการ worksheets — และแม้แต่ charts — แสดงผลโดยตรงเป็น PNG / SVG;
  • พอร์ทัลต้องการ snippet HTML / HTML-Table ที่สะอาดเพื่อฝัง;
  • มีคนต้องการทำให้ไฟล์ .xls / .xlsx / .csv / .ods จำนวนมากเป็นรูปแบบเดียวกัน.

คำตอบแบบเก่า — การติดตั้ง Excel ในเครื่องพร้อมแมโคร หรือคอมโพเนนต์ COM ขนาดใหญ่บนเซิร์ฟเวอร์ของคุณ — ทำให้การขยายขนาดเป็นเรื่องยากและยากต่อการทำงานข้ามแพลตฟอร์ม Aspose.Cells Cloud แทนที่ทั้งหมดนั้นด้วย REST API แท้: upload a file, get a new-format file back.

โพสต์นี้จะอธิบายการใช้งาน API การแปลงสามตัวที่เปิดให้บริการโดย ConversionController แกนหลักในไมโครเซอร์วิส Aspose.Cells Cloud (แหล่งที่มา: src/Aspose.Cells.Cloud.MicroService/Controllers/ConversionController.cs), พร้อมตัวอย่างที่สามารถรันได้ใน cURL, C# (.NET), Python, และ Java.

1. ฟีเจอร์ Convert ทำอะไรได้บ้าง?

ConversionController คือคอนโทรลเลอร์ที่ทุ่มเทให้กับ การแปลงรูปแบบ / การส่งออก มันห่อหุ้มการแปลงระดับเอนจินที่มีความแม่นยำสูงเป็นสามชุดของ API HTTP:

# Scenario Typical endpoint What it does
1 ไฟล์ที่มีอยู่แล้วในคลาวด์สตอเรจ → ดาวน์โหลดในรูปแบบใหม่ GET /v4.0/cells/{name}?format=pdf แปลงเวิร์กบุ๊กโดยตรงในคลาวด์สตอเรจและสตรีมผลลัพธ์กลับ — ไฟล์ขนาดใหญ่ไม่ต้องถูกส่งไปยังเครื่องของคุณ
2 ไฟล์ในเครื่อง → การแปลงออนไลน์ (คุณลักษณะเด่น) PUT /v4.0/cells/convert/spreadsheet?format=pdf คุณอัปโหลดไฟล์ในส่วนของ body ของคำขอ (multipart); เซิร์ฟเวอร์จะแปลงและส่งไฟล์ผลลัพธ์กลับโดยตรง
3 ไฟล์ในคลาวด์ → บันทึกเป็นรูปแบบใหม่, กลับไปยังคลาวด์สตอเรจ PUT /v4.0/cells/{name}/saveas?format=pdf ไฟล์ที่แปลงแล้วจะถูกเขียนกลับไปยังคลาวด์สตอเรจโดยตรง — เหมาะสำหรับสายงานอัตโนมัติ

บันทึกการใช้งาน: เส้นทางต้นทางใช้คำนำหน้า v{version}/cells พร้อมเวอร์ชัน API 4.0 ดังนั้นการเรียกใช้งานจริงจะมีลักษณะเช่น https://api.aspose.cloud/v4.0/cells/....

ความละเอียดของการแปลงเกินกว่าที่ “ไฟล์ทั้งหมด”

นอกจากการแปลงทั้งเวิร์กบุ๊กแล้ว ตัวควบคุมยังสามารถส่งออก องค์ประกอบเดียว:

  • เฉพาะ worksheet → PDF / image / CSV / JSON / HTML
  • ช่วง cell range เฉพาะ (เช่น A1:C12) → PDF / image / CSV / JSON / HTML
  • table เฉพาะ → PDF / image / CSV / JSON / HTML
  • chart เฉพาะ → PNG / JPEG / BMP / GIF / SVG / TIFF / EMF / PDF

ดังนั้นคุณไม่จำเป็นต้องแปลงสมุดงานขนาด 50 MB ทั้งหมดเพียงเพื่อดึงแผนภูมิเดียว — แปลงเฉพาะสิ่งที่คุณต้องการและประหยัดแบนด์วิธและการประมวลผล

2. รูปแบบใดบ้างที่รองรับ?

โดยอิงจากรีจิสทรี ExportData ที่สร้างไว้ในคอนโทรลเลอร์, เมทริกซ์การแปลงจะมีลักษณะโดยประมาณดังนี้:

ประเภท รูปแบบ
นำเข้าและส่งออก (สองทาง) XLS, XLSX, XLSB, XLSM, CSV, TSV, ODS, TXT
ส่งออกเท่านั้น PDF, OTS, XPS, DIF, HTML / MHTML, JSON, PNG, JPEG, BMP, SVG, TIFF, EMF, NUMBERS, FODS, Markdown, DOCX, PPTX, SQL, etc.

โดยสรุป: spreadsheet-to-spreadsheet การแปลงทุกประเภท, บวก ทั้งครอบครัวของการแปลง spreadsheet → PDF / image / web-data ทั้งหมด — ทั้งหมดอยู่ภายใต้ API หนึ่งเดียว.

3. สิ่งที่คุณต้องมีสองอย่างก่อนเริ่มต้น

  1. ลงทะเบียนบัญชีฟรีบน แดชบอร์ด Aspose Cloud และสร้างแอปพลิเคชันเพื่อรับ Client ID และ Client Secret (SDK จะทำการแลกเปลี่ยนเหล่านี้เป็น JWT โดยอัตโนมัติ — ไม่จำเป็นต้องสร้างส่วนหัวการตรวจสอบด้วยตนเอง)
  2. ติดตั้ง SDK สำหรับภาษาที่คุณเลือก:
<!-- .NET -->
<PackageReference Include="Aspose.Cells-Cloud" Version="25.x" />
# Python
pip install asposecellscloud
<!-- Java (Maven) — note: NOT on Maven Central, so the Aspose repo below is required -->
<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.cloud/repo/</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-cells-cloud</artifactId>
    <version>26.8</version>
</dependency>

ไม่ต้องใช้ SDK? ทุกอย่างเป็น REST ธรรมดา ดังนั้น cURL ทำงานได้เช่นกัน (ดูด้านล่าง)


4. กรณีที่ 1: แปลงไฟล์ Excel ในเครื่องเป็นออนไลน์ (หัวข้อ Convert API)

This is PUT /v4.0/cells/convert/spreadsheet — the flagship “Convert” API: อัปโหลดไฟล์ในเครื่องของคุณในส่วนของ request body, เซิร์ฟเวอร์จะแปลงไฟล์และสตรีมไฟล์ใหม่กลับมา. ไม่มีการเก็บข้อมูลใด ๆ ในคลาวด์สตอเรจและไม่มีสำเนาการอัปโหลดค้างอยู่ — เหมาะอย่างยิ่งสำหรับช่วงเวลาที่ต้องการ “just convert this for me”.

① cURL

# 1) First, get a token
curl -X POST "https://api.aspose.cloud/connect/token" \
  -d "grant_type=client_credentials" \
  -d "client_id=YOUR_CLIENT_ID" \
  -d "client_secret=YOUR_CLIENT_SECRET"

# 2) XLSX -> PDF
curl -X PUT "https://api.aspose.cloud/v4.0/cells/convert/spreadsheet?format=pdf" \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@Book1.xlsx" \
  -o Book1.pdf

สลับ format เป็น csv, json, png, xlsx… แล้วคุณจะได้รูปแบบนั้น. หนึ่งพารามิเตอร์ หนึ่งรูปแบบผลลัพธ์.

② C# / .NET

using Aspose.Cells.Cloud.SDK.Api;
using Aspose.Cells.Cloud.SDK.Request;

var cellsApi = new CellsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");

var request = new ConvertSpreadsheetRequest(
    spreadsheet: "C:/invoices/Book1.xlsx",   // local file path
    format: "pdf");                          // target: pdf / csv / json / png ...

using Stream result = cellsApi.ConvertSpreadsheet(request); // converted file stream
using var outFile = File.Create("C:/invoices/Book1.pdf");
result.CopyTo(outFile);

// Even simpler: point the SDK at an output path and let it write the file
// cellsApi.ConvertSpreadsheet(request, "C:/invoices/Book1.pdf");

ต้องการงานแบบแบตช์? ใส่โค้ดนี้ลงในลูปที่วนผ่านไดเรกทอรีและคุณจะได้ “แปลงโฟลเดอร์ทั้งหมด XLSX → PDF”.

③ Python

from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.requests import ConvertSpreadsheetRequest
import os

instance = CellsApi(
    os.getenv('CellsCloudClientId'),
    os.getenv('CellsCloudClientSecret'))

# Local XLSX -> PDF, result written locally
instance.convert_spreadsheet(
    ConvertSpreadsheetRequest("Book1.xlsx", "pdf"),
    local_outpath="Book1.pdf")

# Other formats: just change the parameter — json / csv / xlsx / png ...

④ Java

import com.aspose.cloud.cells.api.CellsApi;
import com.aspose.cloud.cells.request.ConvertSpreadsheetRequest;
import java.io.File;

public class ConvertDemo {
    public static void main(String[] args) throws Exception {
        CellsApi api = new CellsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");

ConvertSpreadsheetRequest req = new ConvertSpreadsheetRequest();
        req.setSpreadsheet("C:/invoices/Book1.xlsx");   // local file path
        req.setFormat("pdf");                           // target: pdf / csv / json / png ...

File out = api.convertSpreadsheet(req);         // converted result as a File
        out.renameTo(new File("C:/invoices/Book1.pdf"));
        System.out.println("Converted: " + out.getAbsolutePath());
    }
}

สี่ภาษา หนึ่งการกระทำ: ระบุเส้นทาง + พารามิเตอร์รูปแบบ → รับไฟล์เป้าหมายกลับ. นั่นคือจุดขายทั้งหมดของ Convert API — ไม่ต้องพึ่งพา Excel ใด ๆ ฝั่งผู้เรียกใช้, ไม่มีเทมเพลต, ไม่มีคอมโพเนนต์ COM.


5. สถานการณ์ที่ 2: แปลงไฟล์ที่จัดเก็บบนคลาวด์โดยตรง

เมื่อไฟล์มีอยู่แล้วใน Aspose Cloud Storage (หรือที่เก็บวัตถุของคุณ) คุณไม่จำเป็นต้องดาวน์โหลด/อัปโหลดไฟล์ขนาดใหญ่ — การแปลงจะเกิดขึ้นในคลาวด์ ลดการถ่ายโอนข้อมูลและปรับปรุงประสิทธิภาพสำหรับสมุดงานขนาดใหญ่.

# cloud Book1.xlsx -> PDF, downloaded locally
curl -G "https://api.aspose.cloud/v4.0/cells/Book1.xlsx" \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "format=pdf" \
  --data-urlencode "folder=Reports" \
  -o Book1.pdf
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.requests import ExportSpreadsheetAsFormatRequest

instance = CellsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")

# Convert a cloud-stored workbook straight to PDF
instance.export_spreadsheet_as_format(
    ExportSpreadsheetAsFormatRequest("Book1.xlsx", format="pdf", folder="Reports"))

คุณยังสามารถเจาะลึกไปยังองค์ประกอบเดียว — เช่น เรนเดอร์ “แผนภูมิที่ 3 บน Sheet1” เป็น PNG (รูปแบบ cloud-storage):

# chart -> PNG
curl -G "https://api.aspose.cloud/v4.0/cells/Book1.xlsx/worksheets/Sheet1/charts/2" \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "format=png" \
  -o chart.png

จุดเชื่อมต่อคลาวด์แบบละเอียดในมุมมองรวดเร็ว:

เป้าหมาย ปลายทาง ตัวอย่าง format
ทั้งเวิร์กบุ๊ก GET /v4.0/cells/{name} pdf / xlsx / csv / json
แผ่นงานเดียว GET /v4.0/cells/{name}/worksheets/{ws} pdf / png / svg
ช่วงเดียว GET /v4.0/cells/{name}/worksheets/{ws}/ranges/{range} pdf / csv / json / html / png
ตารางเดียว GET /v4.0/cells/{name}/worksheets/{ws}/tables/{table} pdf / csv / json / html / png
แผนภูมิเดียว GET /v4.0/cells/{name}/worksheets/{ws}/charts/{index} pdf / png / jpeg / svg / tiff

6. สถานการณ์ที่ 3: SaveAs — เขียนผลลัพธ์กลับไปยังคลาวด์สตอเรจ

เมื่อคุณต้องการให้ไฟล์ที่แปลงแล้ว บันทึกกลับไปยังคลาวด์สตอเรจ (แทนที่จะดาวน์โหลด) ให้ใช้ PUT /v4.0/cells/{name}/saveas มันเหมาะอย่างยิ่งสำหรับการทำอัตโนมัติ เช่น “ส่งออกรายงานของวันนี้เป็น PDF เพื่อการเก็บรักษา ทุกวัน”:

curl -X PUT "https://api.aspose.cloud/v4.0/cells/Book1.xlsx/saveas?format=pdf" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.requests import SaveSpreadsheetAsRequest

instance = CellsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
instance.save_spreadsheet_as(
    SaveSpreadsheetAsRequest("Book1.xlsx", format="pdf", folder="Reports"))
# Result is saved directly in cloud storage; returns CellsCloudResponse(Code=200, Status="OK")

คุณสามารถส่งตัวเลือกการบันทึกแบบละเอียดผ่านส่วนของคำขอ SaveOptionsData และควบคุม ชื่อไฟล์ผลลัพธ์, ที่เก็บผลลัพธ์, ฟอนต์ที่กำหนดเอง, ภูมิภาค/โลคัล, รหัสผ่าน, เป็นต้น ผ่านพารามิเตอร์ query — รายละเอียดเพิ่มเติมเกี่ยวกับสิ่งเหล่านี้อยู่ในส่วน รายละเอียดด้านวิศวกรรม ด้านล่าง.


7. เพิ่ม endpoint “online convert” ที่เตรียมไว้ล่วงหน้า

นอกเหนือจากการแปลงระดับ workbook ที่กล่าวมาข้างต้น ตัวควบคุมยังเปิดเผยชุดเต็มของ endpoint local-file → specific-target (อัปโหลด request-body เช่นเดียวกับ Scenario 1) ซึ่งมีความละเอียดมากขึ้นและใช้แบนด์วิดท์น้อยลง:

Goal Endpoint (PUT, prefix /v4.0/cells/convert/)
สมุดงาน → PDF / JSON / CSV spreadsheet/pdf, spreadsheet/json, spreadsheet/csv
แผ่นงาน → PDF / JSON / CSV / HTML / HTML-Table worksheet/pdf, worksheet/json, worksheet/csv, worksheet/html, worksheet/html-table
แผ่นงาน → image worksheet/image?worksheet=Sheet1&format=png
ช่วง → PDF / CSV / HTML / JSON / image range/pdf, range/csv, range/html, range/json, range/image?worksheet=..&range=A1:C12&format=png
ตาราง → PDF / CSV / HTML / JSON / image table/pdf, table/csv, table/html, table/json, table/image
แผนภูมิ → image / PDF chart/image?worksheet=..&chartIndex=0&format=png, chart/pdf

เช่น “export just this range as CSV for the downstream system”:

curl -X PUT "https://api.aspose.cloud/v4.0/cells/convert/range/csv" \
  -H "Authorization: Bearer $TOKEN" \
  --data-urlencode "worksheet=Sheet1" \
  --data-urlencode "range=A1:C100" \
  -F "file=@data.xlsx" \
  -o data.csv

These endpoints use the same upload-in-the-body pattern as convert/spreadsheet. In the .NET SDK the chart cases have typed wrappers that map to these v4.0 routes — ConvertChartToImage (convert/chart/image) and ConvertChartToPdf (convert/chart/pdf). The worksheet/*, range/* and table/* variants have no v4.0 wrapper yet, so call them over plain REST exactly as the cURL above does.


8. รายละเอียดด้านวิศวกรรมและการจัดการข้อผิดพลาด

ตัวเลือกการแปลงที่ควรรู้ (พารามิเตอร์ query)

  • password — เปิดเวิร์กบุ๊กที่มีการป้องกันด้วยรหัสผ่าน;
  • fontsLocation / custom-font support — ทำให้เกลฟ์ถูกต้องเมื่อเรนเดอร์ PDF/รูปภาพ;
  • ปรับขนาดแถว/คอลัมน์อัตโนมัติ, และกำหนดว่าจะพิมพ์หัวแถว/คอลัมน์ (printHeadings) หรือไม่, การตั้งค่าภูมิภาค/หน้า (region), เป็นต้น;
  • ด้านผลลัพธ์: outPath / outStorageName กำหนดว่าผลลัพธ์จะถูกเก็บไว้ที่ไหนในคลาวด์สตอเรจ.

รหัสข้อผิดพลาด (สัญญาที่คอนโทรลเลอร์บันทึก)

Status Meaning Typical cause
400 คำขอไม่ถูกต้อง URL หรือพารามิเตอร์ไม่ถูกต้อง, หรือ format ที่ไม่รองรับ
401 ไม่ได้รับอนุญาต การตรวจสอบสิทธิ์ล้มเหลวหรือไม่ได้ให้ข้อมูลรับรองที่ถูกต้อง
404 ไม่พบ ไฟล์ต้นทางไม่สามารถเข้าถึงได้ในคลาวด์สตอเรจ
500 ข้อผิดพลาดของเซิร์ฟเวอร์ บริการพบความผิดปกติขณะรับข้อมูลการแปลง

การตรวจสอบสิทธิ์

SDK ทั้งหมดจะทำการรับรองตัวตนโดยอัตโนมัติด้วย OAuth 2.0 client_credentials และ JWT; เมื่อใช้ raw cURL ให้เรียก /connect/token ครั้งแรกก่อน (ดู Scenario 1, ① ข้างต้น).


9. ทำไม Aspose.Cells Cloud Convert?

  • ✅ Zero local dependencies — no Office/Excel, no COM. Callable from any language and any platform (Linux, containers, serverless);
  • ✅ High-fidelity rendering — powered by the Aspose.Cells engine, so formulas, charts, styles, and pagination render at professional quality into PDF/images;
  • ✅ Cloud-native — files can stay in the cloud during conversion to avoid shipping large payloads; pure online conversion needs no cloud storage at all;
  • ✅ Flexible granularity — workbook / worksheet / range / table / chart: convert exactly the piece you need;
  • ✅ One shape across SDKs — the cURL, .NET, Python and Java examples map 1:1, so you can literally copy the pattern you like.

เริ่มต้นเลย: ลงทะเบียนที่ Aspose Cloud Dashboard, สร้างแอปพลิเคชัน, ใส่ข้อมูลประจำตัวของคุณลงในโค้ดตัวอย่างใด ๆ ด้านบน, แล้วรัน — คุณจะมี “ตัวแปลง Excel บนคลาวด์” ของคุณเองในไม่กี่นาที.

พบว่ามีประโยชน์? กดดาว, เพิ่มเป็นบุ๊กมาร์ก หรือแชร์ — และบอกเราเกี่ยวกับกรณีการแปลงสเปรดชีตของคุณในความคิดเห็น.