Update README, godoc and fix typo.
This commit is contained in:
parent
03234d6a25
commit
81146218c7
64
README.md
64
README.md
|
@ -21,7 +21,7 @@ Excelize is a library written in pure Golang and providing a set of functions th
|
||||||
go get github.com/Luxurioust/excelize
|
go get github.com/Luxurioust/excelize
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create XLSX files
|
### Create XLSX file
|
||||||
|
|
||||||
Here is a minimal example usage that will create XLSX file.
|
Here is a minimal example usage that will create XLSX file.
|
||||||
|
|
||||||
|
@ -37,10 +37,14 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
xlsx := excelize.CreateFile()
|
xlsx := excelize.CreateFile()
|
||||||
|
// Create a new sheet.
|
||||||
xlsx.NewSheet(2, "Sheet2")
|
xlsx.NewSheet(2, "Sheet2")
|
||||||
xlsx.NewSheet(3, "Sheet3")
|
// Set int or string type value of a cell.
|
||||||
xlsx.SetCellInt("Sheet2", "A23", 10)
|
xlsx.SetCellValue("Sheet2", "A2", "Hello world.")
|
||||||
xlsx.SetCellStr("Sheet3", "B20", "Hello")
|
xlsx.SetCellValue("Sheet1", "B2", 100)
|
||||||
|
// Set active sheet of workbook.
|
||||||
|
xlsx.SetActiveSheet(2)
|
||||||
|
// Save xlsx file by the given path.
|
||||||
err := xlsx.WriteTo("/tmp/Workbook.xlsx")
|
err := xlsx.WriteTo("/tmp/Workbook.xlsx")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -49,9 +53,9 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Writing XLSX files
|
### Reading XLSX file
|
||||||
|
|
||||||
The following constitutes the bare minimum required to write an XLSX document.
|
The following constitutes the bare to read a XLSX document.
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -69,12 +73,17 @@ func main() {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
xlsx.SetCellValue("Sheet2", "B2", 100)
|
// Get value from cell by given sheet index and axis.
|
||||||
xlsx.SetCellValue("Sheet2", "C7", "Hello")
|
cell := xlsx.GetCellValue("Sheet1", "B2")
|
||||||
xlsx.NewSheet(4, "TestSheet")
|
fmt.Println(cell)
|
||||||
xlsx.SetCellInt("Sheet4", "A3", 10)
|
// Get all the rows in a sheet.
|
||||||
xlsx.SetCellStr("Sheet4", "b6", "World")
|
rows := xlsx.GetRows("Sheet2")
|
||||||
xlsx.SetActiveSheet(2)
|
for _, row := range rows {
|
||||||
|
for _, colCell := range row {
|
||||||
|
fmt.Print(colCell, "\t")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Save the xlsx file with origin path.
|
||||||
err = xlsx.Save()
|
err = xlsx.Save()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
@ -83,30 +92,7 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Reading XLSX files
|
### Add picture to XLSX file
|
||||||
|
|
||||||
```go
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/Luxurioust/excelize"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
xlsx, err := excelize.OpenFile("/tmp/Workbook.xlsx")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
cell := xlsx.GetCellValue("Sheet2", "C7")
|
|
||||||
fmt.Println(cell)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Add picture to XLSX files
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -124,11 +110,11 @@ import (
|
||||||
func main() {
|
func main() {
|
||||||
xlsx := excelize.CreateFile()
|
xlsx := excelize.CreateFile()
|
||||||
// Insert a picture.
|
// Insert a picture.
|
||||||
err := xlsx.AddPicture("Sheet1", "A2", "/tmp/image1.jpg", 0, 0, 1, 1)
|
err := xlsx.AddPicture("Sheet1", "A2", "/tmp/image1.gif", 0, 0, 1, 1)
|
||||||
// Insert a picture to sheet with scaling.
|
// Insert a picture to sheet with scaling.
|
||||||
err = xlsx.AddPicture("Sheet1", "D2", "/tmp/image1.png", 0, 0, 0.5, 0.5)
|
err = xlsx.AddPicture("Sheet1", "D2", "/tmp/image2.jpg", 0, 0, 0.5, 0.5)
|
||||||
// Insert a picture offset in the cell.
|
// Insert a picture offset in the cell.
|
||||||
err = xlsx.AddPicture("Sheet1", "H2", "/tmp/image3.gif", 15, 10, 1, 1)
|
err = xlsx.AddPicture("Sheet1", "H2", "/tmp/image3.png", 15, 10, 1, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
24
picture.go
24
picture.go
|
@ -14,22 +14,22 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddPicture provides the method to add picture in a sheet by given xAxis, yAxis
|
// AddPicture provides the method to add picture in a sheet by given offset
|
||||||
// and file path. For example:
|
// (xAxis, yAxis), scale (xScale, yScale) and file path. For example:
|
||||||
//
|
//
|
||||||
// package main
|
// package main
|
||||||
//
|
//
|
||||||
// import (
|
// import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
// "os"
|
// "os"
|
||||||
// _ "image/gif"
|
// _ "image/gif"
|
||||||
// _ "image/jpeg"
|
// _ "image/jpeg"
|
||||||
// _ "image/png"
|
// _ "image/png"
|
||||||
//
|
//
|
||||||
// "github.com/Luxurioust/excelize"
|
// "github.com/Luxurioust/excelize"
|
||||||
// )
|
// )
|
||||||
//
|
//
|
||||||
// func main() {
|
// func main() {
|
||||||
// xlsx := excelize.CreateFile()
|
// xlsx := excelize.CreateFile()
|
||||||
// // Insert a picture.
|
// // Insert a picture.
|
||||||
// err := xlsx.AddPicture("Sheet1", "A2", "/tmp/image1.jpg", 0, 0, 1, 1)
|
// err := xlsx.AddPicture("Sheet1", "A2", "/tmp/image1.jpg", 0, 0, 1, 1)
|
||||||
|
|
6
sheet.go
6
sheet.go
|
@ -8,9 +8,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSheet provice function to greate a new sheet by given index, when creating
|
// NewSheet provides function to create a new sheet by given index, when
|
||||||
// a new XLSX file, the default sheet will be create, when you create a new
|
// creating a new XLSX file, the default sheet will be create, when you create a
|
||||||
// file, you need to ensure that the index is continuous.
|
// new file, you need to ensure that the index is continuous.
|
||||||
func (f *File) NewSheet(index int, name string) {
|
func (f *File) NewSheet(index int, name string) {
|
||||||
// Update docProps/app.xml
|
// Update docProps/app.xml
|
||||||
f.setAppXML()
|
f.setAppXML()
|
||||||
|
|
Loading…
Reference in New Issue