Skip to content

Commit

Permalink
small wrappers to generate cells
Browse files Browse the repository at this point in the history
  • Loading branch information
nonotest committed Nov 26, 2018
1 parent c4e9df3 commit 7be8888
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions export/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (se SheetExporter) createSheet(srv *sheets.Service, document Document) (*sh

requests := make([]*sheets.Request, 0, 1)
for i, ds := range document.dataSets {
r := se.getFitlerView(s.Sheets[i].Properties.SheetId, len(ds.Data))
r := se.getFilterView(s.Sheets[i].Properties.SheetId, len(ds.Data))
req := &sheets.Request{AddFilterView: r}
requests = append(requests, req)
}
Expand Down Expand Up @@ -139,54 +139,31 @@ func (se SheetExporter) getHeaderRow() *sheets.RowData {
func (se SheetExporter) getUserRow(u models.User) *sheets.RowData {

cells := make([]*sheets.CellData, 0, 2)
handleCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: u.ScreenName,
},
}
cells = append(cells, handleCell)

countCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
NumberValue: float64(u.FollowersCount),
},
}
screenNameCell := getTextCell(u.ScreenName)
cells = append(cells, screenNameCell)

countCell := getNumberCell(u.FollowersCount)
cells = append(cells, countCell)

emailCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: u.Email,
},
}
emailCell := getTextCell(u.Email)
cells = append(cells, emailCell)

nameCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: u.Name,
},
}
nameCell := getTextCell(u.Name)
cells = append(cells, nameCell)

urlCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: u.URL,
},
}
urlCell := getTextCell(u.URL)
cells = append(cells, urlCell)

linkCell := &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: "https://twitter.com/" + u.ScreenName,
},
}
linkCell := getTextCell("https://twitter.com/" + u.ScreenName)
cells = append(cells, linkCell)

return &sheets.RowData{
Values: cells,
}
}

func (se SheetExporter) getFitlerView(sheetID int64, maxRow int) *sheets.AddFilterViewRequest {
func (se SheetExporter) getFilterView(sheetID int64, maxRow int) *sheets.AddFilterViewRequest {
return &sheets.AddFilterViewRequest{
Filter: &sheets.FilterView{
Title: "Sorted Desc",
Expand All @@ -208,3 +185,19 @@ func (se SheetExporter) getFitlerView(sheetID int64, maxRow int) *sheets.AddFilt
},
}
}

func getTextCell(text string) *sheets.CellData {
return &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
StringValue: text,
},
}
}

func getNumberCell(number int64) *sheets.CellData {
return &sheets.CellData{
UserEnteredValue: &sheets.ExtendedValue{
NumberValue: float64(number),
},
}
}

0 comments on commit 7be8888

Please sign in to comment.