-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ docs-vendor: | |
docs-build: docs-vendor | ||
yarn --cwd ./docs build | ||
|
||
docs-publish: docs-build | ||
cd ./docs/src/.vuepress/dist; git init; git add -A; git commit -m 'deploy'; git push -f [email protected]:plandem/xlsx2go.git master:gh-pages; | ||
|
||
docs-dev: docs-vendor | ||
yarn --cwd ./docs dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,153 +1,78 @@ | ||
# Xlsx2Go | ||
[![Build Status](https://travis-ci.org/plandem/xlsx.svg?branch=master)](https://travis-ci.org/plandem/xlsx) | ||
[![Code Coverage](https://codecov.io/gh/plandem/xlsx/branch/master/graph/badge.svg)](https://codecov.io/gh/plandem/xlsx) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/plandem/xlsx)](https://goreportcard.com/report/github.com/plandem/xlsx) | ||
[![GoDoc](https://godoc.org/github.com/plandem/xlsx?status.svg)](https://godoc.org/github.com/plandem/xlsx) | ||
[![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/plandem/xlsx/master/LICENSE) | ||
[![Build Status](https://travis-ci.org/plandem/xlsx2go.svg?branch=master)](https://travis-ci.org/plandem/xlsx2go) | ||
[![Code Coverage](https://codecov.io/gh/plandem/xlsx2go/branch/master/graph/badge.svg)](https://codecov.io/gh/plandem/xlsx2go) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/plandem/xlsx2go)](https://goreportcard.com/report/github.com/plandem/xlsx2go) | ||
[![GoDoc](https://godoc.org/github.com/plandem/xlsx2go?status.svg)](https://godoc.org/github.com/plandem/xlsx2go) | ||
[![License](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/plandem/xlsx2go/master/LICENSE) | ||
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fplandem%2Fxlsx.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fplandem%2Fxlsx?ref=badge_shield) | ||
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/gayvoronsky) | ||
|
||
**Note:** Github repository was renamed from `xlsx` to `xlsx2go` to make it more easier to distinct existing xlsx libraries. Previous address will be auto redirected, package will be named as before - xlsx. | ||
|
||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/plandem/xlsx" | ||
"github.com/plandem/xlsx/format/conditional" | ||
"github.com/plandem/xlsx/format/conditional/rule" | ||
"github.com/plandem/xlsx/format/styles" | ||
"github.com/plandem/xlsx/types" | ||
"github.com/plandem/xlsx/types/comment" | ||
"github.com/plandem/xlsx/types/hyperlink" | ||
) | ||
|
||
func main() { | ||
xl, err := xlsx.Open("./test_files/example_simple.xlsx") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
xl := xlsx.New() | ||
defer xl.Close() | ||
|
||
redBoldYellow := xl.AddStyles( | ||
styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
styles.Fill.Type(styles.PatternTypeSolid), | ||
styles.Fill.Color("#FFFF00"), | ||
), | ||
) | ||
|
||
//iterating via indexes | ||
sheet := xl.Sheet(0) | ||
iMaxCol, iMaxRow := sheet.Dimension() | ||
for iRow := 0; iRow < iMaxRow; iRow++ { | ||
for iCol := 0; iCol < iMaxCol; iCol++ { | ||
if iRow % 2 == 0 && iCol % 2 == 0 { | ||
cell := sheet.Cell(iCol, iRow) | ||
cell.SetStyles(redBoldYellow) | ||
} | ||
} | ||
} | ||
//create a new sheet | ||
sheet := xl.AddSheet("The first sheet") | ||
|
||
//iterating via iterators | ||
for rows := sheet.Rows(); rows.HasNext(); { | ||
_, row := rows.Next() | ||
|
||
for cells := row.Cells(); cells.HasNext(); { | ||
iCol, iRow, cell := cells.Next() | ||
if iRow % 2 == 0 && iCol % 2 == 0 { | ||
cell.SetStyles(redBoldYellow) | ||
} | ||
} | ||
} | ||
|
||
//walk through the range's cells | ||
for rows := sheet.Rows(); rows.HasNext(); { | ||
_, row := rows.Next() | ||
row.Walk(func(idx, iCol, iRow int, cell *xlsx.Cell) { | ||
if iRow % 2 == 0 && iCol % 2 == 0 { | ||
cell.SetStyles(redBoldYellow) | ||
} | ||
}) | ||
} | ||
|
||
//Add hyperlink and set value same time | ||
sheet.CellByRef("A1").SetValueWithHyperlink("Link To Google", "http://google.com") | ||
|
||
//Add hyperlink as string | ||
sheet.RangeByRef("B1:C3").SetHyperlink("[email protected]") | ||
|
||
//Add hyperlink via helper type for advanced settings | ||
sheet.CellByRef("A7").SetHyperlink(hyperlink.New( | ||
hyperlink.ToFile("./example_simple.xlsx"), | ||
hyperlink.ToRef("C3", "Sheet1"), | ||
hyperlink.Tooltip("That's a tooltip"), | ||
hyperlink.Display("Something to display"), //Cell still holds own value | ||
hyperlink.Styles(redBoldYellow), | ||
)) | ||
//access by ref | ||
cell := sheet.CellByRef("A2") | ||
|
||
sheet.CellByRef("A1").RemoveHyperlink() | ||
|
||
//Merged Cells | ||
sheet.RangeByRef("A1:C3").Merge() | ||
sheet.RangeByRef("A1:C3").Split() | ||
|
||
//Rich Text | ||
sheet.CellByRef("F10").SetText( | ||
"plain text", | ||
styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
), | ||
" red bold text ", | ||
"another plain text", | ||
) | ||
|
||
//Add comment as string | ||
sheet.CellByRef("F11").SetComment("A cell's comment") | ||
|
||
//Add comment via helper type for advanced settings | ||
sheet.CellByRef("F12").SetComment(comment.New( | ||
comment.Author("John Doe"), | ||
comment.Text( | ||
"plain text", | ||
styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
), | ||
" red bold text ", | ||
"another plain text", | ||
), | ||
//set value | ||
cell.SetValue("Easy Peasy") | ||
|
||
//set cool styles | ||
cell.SetStyles(styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
styles.Fill.Type(styles.PatternTypeSolid), | ||
styles.Fill.Color("#ffff00"), | ||
styles.Border.Color("#009000"), | ||
styles.Border.Type(styles.BorderStyleMedium), | ||
)) | ||
|
||
sheet.CellByRef("F11").RemoveComment() | ||
|
||
//Conditional formatting | ||
|
||
//add comment | ||
cell.SetComment("No Comment!") | ||
|
||
//add hyperlink | ||
sheet.CellByRef("A4").SetValueWithHyperlink("wikipedia", "http://google.com") | ||
|
||
//merge cells | ||
sheet.RangeByRef("A6:A7").Merge() | ||
sheet.CellByRef("A6").SetValue("merged cell") | ||
|
||
//iterating | ||
for iRow := 1; iRow < 7; iRow++ { | ||
//access by indexes | ||
cell := sheet.Cell(1, iRow) | ||
cell.SetValue(iRow) | ||
} | ||
|
||
//add conditional formatting | ||
sheet.AddConditional(conditional.New( | ||
conditional.AddRule( | ||
rule.Value.Between(35.5, 78, styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
)), | ||
), | ||
conditional.AddRule( | ||
rule.TimePeriod.Last7Days(styles.New( | ||
rule.Value.Between(1, 3, styles.New( | ||
styles.Font.Bold, | ||
styles.Font.Color("#ff0000"), | ||
)), | ||
), | ||
conditional.AddRule( | ||
rule.IconSet.Type(rule.IconSetType3Arrows), | ||
rule.IconSet.Value(0, "90", ">="), | ||
rule.IconSet.Value(1, "50", ">"), | ||
), | ||
), "A1:A10", "B2", "C1:C10") | ||
xl.SaveAs("test1.xlsx") | ||
), "B2:B7") | ||
|
||
xl.SaveAs("./foo.xlsx") | ||
} | ||
``` | ||
|
||
|
@@ -174,6 +99,10 @@ So what were the goals that time? It's a great pity, but I could not get a libra | |
|
||
> I was trying to contribute to existing libraries, but...actually it's much faster to create it from ground zero than to refactor existing and get satisfied results or fix some issues. | ||
## Documentation | ||
* [Guide](https://plandem.github.io/xlsx2go/) | ||
* [API Documentation](https://godoc.org/github.com/plandem/xlsx) | ||
|
||
# Benchmarks | ||
It was not a goal to make best of the best, but the same time it's interesting to know pros/cons. | ||
For some cases this library is second, for other - best, but in case of reading huge files - **the only**. | ||
|
@@ -193,14 +122,11 @@ For some cases this library is second, for other - best, but in case of reading | |
|
||
[Benchmarks report](BENCHMARKS.md) | ||
|
||
# Documentation and Examples | ||
For more detailed documentation and examples you can check [godoc.org](https://godoc.org/github.com/plandem/xlsx) | ||
|
||
# Roadmap | ||
- [ ] sheet: copy | ||
- [x] sheet: read as stream | ||
- [ ] sheet: custom filters | ||
- [ ] sheet: write as stream | ||
- [x] sheet: write as stream | ||
- [x] merged cells: merge/split for ranges, cols, rows | ||
- [x] hyperlinks: for cells, ranges, cols, rows | ||
- [x] range: copy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters