forked from p30928647/excelize
Resolve #580, revert commit 5ca7231ed4
This commit is contained in:
parent
52f1eee7c4
commit
ad883caa0f
45
README.md
45
README.md
|
@ -31,7 +31,11 @@ Here is a minimal example usage that will create XLSX file.
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f := excelize.NewFile()
|
||||
|
@ -44,7 +48,7 @@ func main() {
|
|||
f.SetActiveSheet(index)
|
||||
// Save xlsx file by the given path.
|
||||
if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -56,28 +60,32 @@ The following constitutes the bare to read a XLSX document.
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := excelize.OpenFile("Book1.xlsx")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Get value from cell by given worksheet name and axis.
|
||||
cell, err := f.GetCellValue("Sheet1", "B2")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
println(cell)
|
||||
fmt.Println(cell)
|
||||
// Get all the rows in the Sheet1.
|
||||
rows, err := f.GetRows("Sheet1")
|
||||
for _, row := range rows {
|
||||
for _, colCell := range row {
|
||||
print(colCell, "\t")
|
||||
fmt.Print(colCell, "\t")
|
||||
}
|
||||
println()
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -91,7 +99,11 @@ With Excelize chart generation and management is as easy as a few lines of code.
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
|
||||
|
@ -104,12 +116,12 @@ func main() {
|
|||
f.SetCellValue("Sheet1", k, v)
|
||||
}
|
||||
if err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Save xlsx file by the given path.
|
||||
if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -120,6 +132,7 @@ func main() {
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
|
@ -130,24 +143,24 @@ import (
|
|||
func main() {
|
||||
f, err := excelize.OpenFile("Book1.xlsx")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// Insert a picture.
|
||||
if err := f.AddPicture("Sheet1", "A2", "image.png", ""); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Insert a picture to worksheet with scaling.
|
||||
if err := f.AddPicture("Sheet1", "D2", "image.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Insert a picture offset in the cell with printing support.
|
||||
if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Save the xlsx file with the origin path.
|
||||
if err = f.Save(); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
45
README_zh.md
45
README_zh.md
|
@ -30,7 +30,11 @@ go get github.com/360EntSecGroup-Skylar/excelize
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f := excelize.NewFile()
|
||||
|
@ -43,7 +47,7 @@ func main() {
|
|||
f.SetActiveSheet(index)
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -55,28 +59,32 @@ func main() {
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := excelize.OpenFile("Book1.xlsx")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// 获取工作表中指定单元格的值
|
||||
cell, err := f.GetCellValue("Sheet1", "B2")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
println(cell)
|
||||
fmt.Println(cell)
|
||||
// 获取 Sheet1 上所有单元格
|
||||
rows, err := f.GetRows("Sheet1")
|
||||
for _, row := range rows {
|
||||
for _, colCell := range row {
|
||||
print(colCell, "\t")
|
||||
fmt.Print(colCell, "\t")
|
||||
}
|
||||
println()
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -90,7 +98,11 @@ func main() {
|
|||
```go
|
||||
package main
|
||||
|
||||
import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/360EntSecGroup-Skylar/excelize"
|
||||
)
|
||||
|
||||
func main() {
|
||||
categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
|
||||
|
@ -103,12 +115,12 @@ func main() {
|
|||
f.SetCellValue("Sheet1", k, v)
|
||||
}
|
||||
if err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"}}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// 根据指定路径保存文件
|
||||
if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -119,6 +131,7 @@ func main() {
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "image/gif"
|
||||
_ "image/jpeg"
|
||||
_ "image/png"
|
||||
|
@ -129,24 +142,24 @@ import (
|
|||
func main() {
|
||||
f, err := excelize.OpenFile("Book1.xlsx")
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
// 插入图片
|
||||
if err := f.AddPicture("Sheet1", "A2", "image.png", ""); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// 在工作表中插入图片,并设置图片的缩放比例
|
||||
if err := f.AddPicture("Sheet1", "D2", "image.jpg", `{"x_scale": 0.5, "y_scale": 0.5}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// 在工作表中插入图片,并设置图片的打印属性
|
||||
if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "print_obj": true, "lock_aspect_ratio": false, "locked": false}`); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// 保存文件
|
||||
if err = f.Save(); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -110,7 +110,7 @@ func ExampleFile_SetCellFloat() {
|
|||
f := NewFile()
|
||||
var x = 3.14159265
|
||||
if err := f.SetCellFloat("Sheet1", "A1", x, 2, 64); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
val, _ := f.GetCellValue("Sheet1", "A1")
|
||||
fmt.Println(val)
|
||||
|
|
20
chart.go
20
chart.go
|
@ -503,7 +503,11 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
|
|||
//
|
||||
// package main
|
||||
//
|
||||
// import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
// import (
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/360EntSecGroup-Skylar/excelize"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
|
||||
|
@ -516,12 +520,12 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
|
|||
// f.SetCellValue("Sheet1", k, v)
|
||||
// }
|
||||
// if err := f.AddChart("Sheet1", "E1", `{"type":"col3DClustered","series":[{"name":"Sheet1!$A$2","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"},{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"title":{"name":"Fruit 3D Clustered Column Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true},"show_blanks_as":"zero","x_axis":{"reverse_order":true},"y_axis":{"maximum":7.5,"minimum":0.5}}`); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// // Save xlsx file by the given path.
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
@ -697,7 +701,11 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
|
|||
//
|
||||
// package main
|
||||
//
|
||||
// import "github.com/360EntSecGroup-Skylar/excelize"
|
||||
// import (
|
||||
// "fmt"
|
||||
//
|
||||
// "github.com/360EntSecGroup-Skylar/excelize"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// categories := map[string]string{"A2": "Small", "A3": "Normal", "A4": "Large", "B1": "Apple", "C1": "Orange", "D1": "Pear"}
|
||||
|
@ -710,12 +718,12 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
|
|||
// f.SetCellValue("Sheet1", k, v)
|
||||
// }
|
||||
// if err := f.AddChart("Sheet1", "E1", `{"type":"col","series":[{"name":"Sheet1!$A$2","categories":"","values":"Sheet1!$B$2:$D$2"},{"name":"Sheet1!$A$3","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$3:$D$3"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"title":{"name":"Clustered Column - Line Chart"},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true}}`, `{"type":"line","series":[{"name":"Sheet1!$A$4","categories":"Sheet1!$B$1:$D$1","values":"Sheet1!$B$4:$D$4"}],"format":{"x_scale":1.0,"y_scale":1.0,"x_offset":15,"y_offset":10,"print_obj":true,"lock_aspect_ratio":false,"locked":false},"legend":{"position":"left","show_legend_key":false},"plotarea":{"show_bubble_size":true,"show_cat_name":false,"show_leader_lines":false,"show_percent":true,"show_series_name":true,"show_val":true}}`); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// // Save xlsx file by the given path.
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
|
|
@ -294,13 +294,13 @@ func (f *File) UpdateLinkedValue() error {
|
|||
// functions and/or macros. The file extension should be .xlsm. For example:
|
||||
//
|
||||
// if err := f.SetSheetPrOptions("Sheet1", excelize.CodeName("Sheet1")); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.AddVBAProject("vbaProject.bin"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("macros.xlsm"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
func (f *File) AddVBAProject(bin string) error {
|
||||
|
|
|
@ -1259,7 +1259,7 @@ func fillCells(f *File, sheet string, colCount, rowCount int) {
|
|||
for row := 1; row <= rowCount; row++ {
|
||||
cell, _ := CoordinatesToCellName(col, row)
|
||||
if err := f.SetCellStr(sheet, cell, cell); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
picture.go
21
picture.go
|
@ -59,18 +59,18 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
|
|||
// f := excelize.NewFile()
|
||||
// // Insert a picture.
|
||||
// if err := f.AddPicture("Sheet1", "A2", "image.jpg", ""); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Insert a picture scaling in the cell with location hyperlink.
|
||||
// if err := f.AddPicture("Sheet1", "D2", "image.png", `{"x_scale": 0.5, "y_scale": 0.5, "hyperlink": "#Sheet2!D8", "hyperlink_type": "Location"}`); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// // Insert a picture offset in the cell with external hyperlink, printing and positioning support.
|
||||
// if err := f.AddPicture("Sheet1", "H2", "image.gif", `{"x_offset": 15, "y_offset": 10, "hyperlink": "https://github.com/360EntSecGroup-Skylar/excelize", "hyperlink_type": "External", "print_obj": true, "lock_aspect_ratio": false, "locked": false, "positioning": "oneCell"}`); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
@ -104,6 +104,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
|
|||
// package main
|
||||
//
|
||||
// import (
|
||||
// "fmt"
|
||||
// _ "image/jpeg"
|
||||
// "io/ioutil"
|
||||
//
|
||||
|
@ -115,13 +116,13 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
|
|||
//
|
||||
// file, err := ioutil.ReadFile("image.jpg")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.AddPictureFromBytes("Sheet1", "A2", "", "Excel Logo", ".jpg", file); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
@ -424,16 +425,16 @@ func (f *File) getSheetRelationshipsTargetByID(sheet, rID string) string {
|
|||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// file, raw, err := f.GetPicture("Sheet1", "A2")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// if err := ioutil.WriteFile(file, raw, 0644); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
func (f *File) GetPicture(sheet, cell string) (string, []byte, error) {
|
||||
|
|
|
@ -63,10 +63,10 @@ type PivotTableOption struct {
|
|||
// Columns: []string{"Type"},
|
||||
// Data: []string{"Sales"},
|
||||
// }); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := f.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
|
16
rows.go
16
rows.go
|
@ -25,18 +25,18 @@ import (
|
|||
//
|
||||
// rows, err := f.Rows("Sheet1")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for rows.Next() {
|
||||
// row, err := rows.Columns()
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, colCell := range row {
|
||||
// print(colCell, "\t")
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// println()
|
||||
// fmt.Println()
|
||||
// }
|
||||
//
|
||||
func (f *File) GetRows(sheet string) ([][]string, error) {
|
||||
|
@ -152,18 +152,18 @@ func (err ErrSheetNotExist) Error() string {
|
|||
//
|
||||
// rows, err := f.Rows("Sheet1")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
// }
|
||||
// for rows.Next() {
|
||||
// row, err := rows.Columns()
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for _, colCell := range row {
|
||||
// print(colCell, "\t")
|
||||
// fmt.Print(colCell, "\t")
|
||||
// }
|
||||
// println()
|
||||
// fmt.Println()
|
||||
// }
|
||||
//
|
||||
func (f *File) Rows(sheet string) (*Rows, error) {
|
||||
|
|
2
sheet.go
2
sheet.go
|
@ -344,7 +344,7 @@ func (f *File) GetSheetIndex(name string) int {
|
|||
// return
|
||||
// }
|
||||
// for index, name := range f.GetSheetMap() {
|
||||
// println(index, name)
|
||||
// fmt.Println(index, name)
|
||||
// }
|
||||
//
|
||||
func (f *File) GetSheetMap() map[int]string {
|
||||
|
|
|
@ -19,7 +19,7 @@ func ExampleFile_SetPageLayout() {
|
|||
"Sheet1",
|
||||
excelize.PageLayoutOrientation(excelize.OrientationLandscape),
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := f.SetPageLayout(
|
||||
"Sheet1",
|
||||
|
@ -27,7 +27,7 @@ func ExampleFile_SetPageLayout() {
|
|||
excelize.FitToHeight(2),
|
||||
excelize.FitToWidth(2),
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Output:
|
||||
}
|
||||
|
@ -41,17 +41,17 @@ func ExampleFile_GetPageLayout() {
|
|||
fitToWidth excelize.FitToWidth
|
||||
)
|
||||
if err := f.GetPageLayout("Sheet1", &orientation); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := f.GetPageLayout("Sheet1", &paperSize); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := f.GetPageLayout("Sheet1", &fitToHeight); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetPageLayout("Sheet1", &fitToWidth); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("Defaults:")
|
||||
fmt.Printf("- orientation: %q\n", orientation)
|
||||
|
|
|
@ -40,7 +40,7 @@ func ExampleFile_SetSheetPrOptions() {
|
|||
excelize.AutoPageBreaks(true),
|
||||
excelize.OutlineSummaryBelow(false),
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Output:
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func ExampleFile_GetSheetPrOptions() {
|
|||
&autoPageBreaks,
|
||||
&outlineSummaryBelow,
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("Defaults:")
|
||||
fmt.Printf("- codeName: %q\n", codeName)
|
||||
|
@ -189,7 +189,7 @@ func ExampleFile_SetPageMargins() {
|
|||
excelize.PageMarginRight(1.0),
|
||||
excelize.PageMarginTop(1.0),
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Output:
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ func ExampleFile_GetPageMargins() {
|
|||
&marginRight,
|
||||
&marginTop,
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("Defaults:")
|
||||
fmt.Println("- marginBottom:", marginBottom)
|
||||
|
|
|
@ -47,7 +47,7 @@ func ExampleFile_SetSheetViewOptions() {
|
|||
excelize.ZoomScale(80),
|
||||
excelize.TopLeftCell("C3"),
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
var zoomScale excelize.ZoomScale
|
||||
|
@ -55,22 +55,22 @@ func ExampleFile_SetSheetViewOptions() {
|
|||
fmt.Println("- zoomScale: 80")
|
||||
|
||||
if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(500)); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("Used out of range value:")
|
||||
fmt.Println("- zoomScale:", zoomScale)
|
||||
|
||||
if err := f.SetSheetViewOptions(sheet, 0, excelize.ZoomScale(123)); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetSheetViewOptions(sheet, 0, &zoomScale); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("Used correct value:")
|
||||
|
@ -111,7 +111,7 @@ func ExampleFile_GetSheetViewOptions() {
|
|||
&zoomScale,
|
||||
&topLeftCell,
|
||||
); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("Default:")
|
||||
|
@ -125,27 +125,27 @@ func ExampleFile_GetSheetViewOptions() {
|
|||
fmt.Println("- topLeftCell:", `"`+topLeftCell+`"`)
|
||||
|
||||
if err := f.SetSheetViewOptions(sheet, 0, excelize.TopLeftCell("B2")); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetSheetViewOptions(sheet, 0, &topLeftCell); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.SetSheetViewOptions(sheet, 0, excelize.ShowGridLines(false)); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetSheetViewOptions(sheet, 0, &showGridLines); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.SetSheetViewOptions(sheet, 0, excelize.ShowZeros(false)); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
if err := f.GetSheetViewOptions(sheet, 0, &showZeros); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
fmt.Println("After change:")
|
||||
|
|
|
@ -298,12 +298,12 @@ func prepareSparklineDataset() *File {
|
|||
f.NewSheet("Sheet3")
|
||||
for row, data := range sheet2 {
|
||||
if err := f.SetSheetRow("Sheet2", fmt.Sprintf("A%d", row+1), &data); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
for row, data := range sheet3 {
|
||||
if err := f.SetSheetRow("Sheet3", fmt.Sprintf("A%d", row+1), &data); err != nil {
|
||||
println(err.Error())
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
return f
|
||||
|
|
12
stream.go
12
stream.go
|
@ -42,14 +42,14 @@ type StreamWriter struct {
|
|||
// file := excelize.NewFile()
|
||||
// streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// styleID, err := file.NewStyle(`{"font":{"color":"#777777"}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data"}}); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// for rowID := 2; rowID <= 102400; rowID++ {
|
||||
// row := make([]interface{}, 50)
|
||||
|
@ -58,14 +58,14 @@ type StreamWriter struct {
|
|||
// }
|
||||
// cell, _ := excelize.CoordinatesToCellName(1, rowID)
|
||||
// if err := streamWriter.SetRow(cell, row); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// }
|
||||
// if err := streamWriter.Flush(); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// if err := file.SaveAs("Book1.xlsx"); err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
//
|
||||
func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
|
||||
|
|
16
styles.go
16
styles.go
|
@ -2321,7 +2321,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2330,7 +2330,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2338,7 +2338,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2346,7 +2346,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2357,7 +2357,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
// f.SetCellValue("Sheet1", "H9", 42920.5)
|
||||
// style, err := f.NewStyle(`{"number_format": 22}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2365,7 +2365,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Times New Roman","size":36,"color":"#777777"}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2373,7 +2373,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) {
|
|||
//
|
||||
// style, err := f.NewStyle(`{"protection":{"hidden":true, "locked":true}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// err = f.SetCellStyle("Sheet1", "H9", "H9", style)
|
||||
//
|
||||
|
@ -2507,7 +2507,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error {
|
|||
//
|
||||
// format, err = f.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// fmt.Println(err)
|
||||
// }
|
||||
// f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format))
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue