Sử dụng trường hợp cho Aspose.Words FOSS cho Python

Sử dụng trường hợp cho Aspose.Words FOSS cho Python

Aspose.Cells FOSS for Python is a pure Python library for creating, reading, and converting spreadsheet files without Microsoft Office. The following use cases illustrate where the library fits into real-world Python applications.


Dữ liệu xuất khẩu đường ống

Chuyển đổi sổ làm việc XLSX sang CSV, Markdown hoặc JSON cho xử lý downstream:

from aspose.cells_foss import Workbook, SaveFormat

wb = Workbook("data.xlsx")
wb.save("data.csv", SaveFormat.CSV)
wb.save("data.md", SaveFormat.MARKDOWN)
wb.save("data.json", SaveFormat.JSON)

Mô hình này hoạt động cho bất kỳ định dạng xuất phát được hỗ trợ. Sử dụng nó để lưu trữ dữ liệu vào các ống tài liệu, máy tạo trang static hoặc phản ứng API.

Xem thêm: Cách lưu các bảng điều khiển trong Python


Báo cáo thế hệ

Xây dựng báo cáo XLSX từ dữ liệu ứng dụng và phục vụ chúng cho người dùng:

wb = Workbook() ws = wb.add_worksheet(“Report”) cells = ws.cells

cells.cell(0, 0).put_value(“Month”) cells.cell(0, 1).put_value(“Revenue”)

rows = [(“Jan”, 12400), (“Feb”, 15200), (“Mar”, 11800)] for i, (month, rev) in enumerate(rows, start=1): cells.cell(i, 0).put_value(month) cells.cell(i, 1).put_value(rev)

wb.save(“monthly_report.xlsx”, SaveFormat.XLSX)


Xem thêm: [Làm thế nào để bắt đầu với Aspose.Email FOSS cho Python](https://kb.aspose.org/cells/python/how-to-get-started-cells-python/)

---

## Batch Spreadsheet xử lý

Thực hiện một thư mục sách làm việc trong một kịch bản duy nhất:

```python
from pathlib import Path
from aspose.cells_foss import Workbook, SaveFormat

for src in Path("incoming/").glob("*.xlsx"):
    wb = Workbook(str(src))
    wb.save(str(src.with_suffix(".csv")), SaveFormat.CSV)

Đọc và chuyển đổi dữ liệu

Tải sổ làm việc, đọc giá trị tế bào và viết kết quả chuyển đổi:

wb = Workbook(“sales.xlsx”) ws = wb.get_worksheet(0) cells = ws.cells

Read all rows and filter

out_wb = Workbook() out_ws = out_wb.add_worksheet(“Filtered”) out_row = 0

for row in ws.cells.iter_rows(0, None, 0, None, values_only=True): if row and row[1] is not None and row[1] > 10000: out_ws.cells.cell(out_row, 0).put_value(row[0]) out_ws.cells.cell(out_row, 1).put_value(row[1]) out_row += 1

out_wb.save(“high_value.xlsx”, SaveFormat.XLSX)


Xem thêm: [Làm thế nào để tải một bảng điều khiển trong Python](https://kb.aspose.org/cells/python/how-to-load-spreadsheet-python/)

---

## Chart tự động hóa

Xây dựng biểu đồ theo chương trình từ dữ liệu bảng điều khiển:

wb = Workbook()
ws = wb.add_worksheet("Sales")
cells = ws.cells

cells.cell(0, 0).put_value("Q1")
cells.cell(0, 1).put_value(4200)
cells.cell(1, 0).put_value("Q2")
cells.cell(1, 1).put_value(5800)

chart = ws.charts.add_bar(0, 2, 20, 10)
chart.series.add("B1:B2", "A1:A2", "Revenue")
chart.title = "Quarterly Revenue"

wb.save("chart_report.xlsx", SaveFormat.XLSX)

Xem thêm: Cách tạo biểu đồ trong Python


See Also

 Tiếng Việt