Skip to content

Commit

Permalink
ADding documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
FerdinaKusumah committed Oct 6, 2020
1 parent d1cef0f commit 71caa7f
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,111 @@
# Convert Excel Or Csv To Json Easily

## Read excel `xlsx` from remote source
```go
import (
"encoding/json"
"fmt"
"github.com/FerdinaKusumah/excel2json"
"log"
)

func main() {
var (
result []*map[string]interface{}
err error
url = "https://www.wisdomaxis.com/technology/software/data/for-reports/Data%20Refresh%20Sample%20Data.xlsx"
sheetName = "Sheet1"
headers = []string{"Profit", "Shipping Cost", "Unit Price"}
)
if result, err = excel2json.GetExcelFileUrl(url, sheetName, headers); err != nil {
log.Fatalf(`unable to parse file, error: %s`, err)
}
for _, val := range result {
result, _ := json.Marshal(val)
fmt.Println(string(result))
}
}
```

## Read excel `xlsx` from local source
```go
import (
"encoding/json"
"fmt"
"github.com/FerdinaKusumah/excel2json"
"log"
)

func main() {
var (
result []*map[string]interface{}
err error
path = "./Data Refresh Sample Data.xlsx"
sheetName = "Sheet1"
headers = []string{"Profit", "Shipping Cost", "Unit Price"}
)
if result, err = excel2json.GetExcelFilePath(path, sheetName, headers); err != nil {
log.Fatalf(`unable to parse file, error: %s`, err)
}
for _, val := range result {
result, _ := json.Marshal(val)
fmt.Println(string(result))
}
}
```

## Read csv from remote source
```go
import (
"encoding/json"
"fmt"
"github.com/FerdinaKusumah/excel2json"
"log"
)

func main() {
var (
result []*map[string]interface{}
err error
url = "https://raw.githubusercontent.com/curran/data/gh-pages/senseYourCity/all.csv"
headers = []string{"humidity", "sound"}
delimited = ","
)
if result, err = excel2json.GetCsvFileUrl(url, delimited, headers); err != nil {
log.Fatalf(`unable to parse file, error: %s`, err)
}
for _, val := range result {
result, _ := json.Marshal(val)
fmt.Println(string(result))
}
}
```

## Read csv from local source
```go
import (
"encoding/json"
"fmt"
"github.com/FerdinaKusumah/excel2json"
"log"
)

func main() {
var (
result []*map[string]interface{}
err error
path = "./all.csv"
headers = []string{"humidity", "sound"}
delimited = ","
)
if result, err = excel2json.GetCsvFilePath(path, delimited, headers); err != nil {
log.Fatalf(`unable to parse file, error: %s`, err)
}
for _, val := range result {
result, _ := json.Marshal(val)
fmt.Println(string(result))
}
}
```

### Contributors are welcome !!

0 comments on commit 71caa7f

Please sign in to comment.