Quickstart
Quickstart
Hướng dẫn này tạo một workbook, ghi một bảng nhỏ các giá trị, áp dụng kiểu tiêu đề in đậm, và lưu kết quả — con đường nhanh nhất từ việc cài đặt đến một tệp .xlsx thực tế.
Prerequisites
| Requirement | Detail |
|---|---|
| Mô-đun đã được cài đặt | Xem Installation |
| Import | import cells_foss "github.com/aspose-cells-foss/Aspose.Cells-FOSS-for-Go/v26/aspose/cells_foss" |
Bước 1: Tạo một workbook và truy cập worksheet đầu tiên
Một Workbook mới luôn bắt đầu với một worksheet, có sẵn thông qua phần Worksheets:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
fmt.Println("Worksheets available:", len(wb.Worksheets))
_ = wsBước 2: Ghi giá trị ô
Sử dụng Cells().Set(ref, value) để ghi một giá trị vào ô bằng tham chiếu kiểu A1:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
ws.Cells().Set("A1", "Product")
ws.Cells().Set("B1", "Revenue")
ws.Cells().Set("A2", "Widget A")
ws.Cells().Set("B2", 42000)Bước 3: In đậm hàng tiêu đề
Tạo một Style với một Font in đậm và áp dụng nó vào các ô tiêu đề bằng Cell.SetStyle:
wb := cells_foss.NewWorkbook()
ws := wb.Worksheets[0]
ws.Cells().Set("A1", "Product")
ws.Cells().Set("B1", "Revenue")
boldStyle := cells_foss.NewStyle()
boldStyle.Font.Bold = true
for _, ref := range []string{"A1", "B1"} {
cell, _ := ws.Cells().Get(ref)
cell.SetStyle(boldStyle)
}Bước 4: Lưu workbook
wb := cells_foss.NewWorkbook()
if err := wb.Save("report.xlsx"); err != nil {
fmt.Printf("Error saving workbook: %v\n", err)
return
}
fmt.Println("Workbook saved to report.xlsx")Mở report.xlsx trong Excel hoặc LibreOffice để xem hàng tiêu đề in đậm và hai ô dữ liệu.
Các bước tiếp theo
- Hướng dẫn nhà phát triển: Tạo kiểu, xác thực dữ liệu, bảng, hình ảnh và đọc luồng
- API Reference: Tài liệu đầy đủ về lớp và phương thức
- Cơ sở kiến thức: Các hướng dẫn thực hiện dựa trên nhiệm vụ