本文整理汇总了Golang中github.com/tealeg/xlsx.Sheet类的典型用法代码示例。如果您正苦于以下问题:Golang Sheet类的具体用法?Golang Sheet怎么用?Golang Sheet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sheet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
var RawNbr int = 4
file = xlsx.NewFile()
sheetName := [2]string{"Big", "Small"}
datafile := [2]string{"../data/moveline/big", "../data/moveline/small"}
for i, v := range sheetName {
sheet = file.AddSheet(v)
// 每列标题
text := [4]string{"ID", "X", "Y", "Angle"}
for i := 0; i < RawNbr; i++ {
if i == 0 {
row = sheet.AddRow()
}
cell = row.AddCell()
cell.Value = text[i]
}
files, _ := ListDir(datafile[i], ".dat")
for j := 0; j < len(files); j++ {
write(files[j], sheet, RawNbr)
}
}
fmt.Println("正在向excel写数据......")
err = file.Save("../outexcel/单条鱼路径.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例2: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
var RawNbr int = 6
file = xlsx.NewFile()
sheet = file.AddSheet("Sheet1")
// 每列标题
text := [6]string{"ID", "鱼类型", "出现帧", "脚本ID", "X", "Y"}
for i := 0; i < RawNbr; i++ {
if i == 0 {
row = sheet.AddRow()
}
cell = row.AddCell()
cell.Value = text[i]
}
files, err := ListDir("../data/timeline", ".dat")
for j := 0; j < len(files); j++ {
write(files[j], sheet, 6)
}
err = file.Save("../outexcel/巡游鱼路径.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例3: getHeader
func getHeader(sheet *xlsx.Sheet) (*tool.ExportHeaderV1, error) {
headerString := strings.TrimSpace(sheet.Cell(0, 0).Value)
// 可能是空的sheet
if headerString == "" {
return nil, nil
}
var header tool.ExportHeaderV1
// 有可能的字符,一定是头
if strings.Contains(headerString, "ProtoTypeName") ||
strings.Contains(headerString, "RowFieldName") {
if err := proto.UnmarshalText(headerString, &header); err != nil {
return nil, err
}
} else {
// 有字符, 但并不是头
return nil, nil
}
return &header, nil
}
示例4: formatterExcel
func (client *TrelloClient) formatterExcel(cards []*TrelloCardSearchResult) (err error) {
var (
file *xlsx.File
sheet *xlsx.Sheet
row *xlsx.Row
cell *xlsx.Cell
)
client.config.QuoteChar = "" // we do not need quoting in excel
file = xlsx.NewFile()
if sheet, err = file.AddSheet("Sheet1"); err != nil {
return
}
for _, card := range cards {
row = sheet.AddRow()
for _, column := range client.buildOutputLine(card) {
cell = row.AddCell()
cell.Value = column
}
}
if err != nil {
fmt.Printf(err.Error())
}
err = file.Write(os.Stdout)
if err != nil {
fmt.Printf(err.Error())
}
return err
}
示例5: write
// 写每一个*.dat数据
func write(infile string, sheet *xlsx.Sheet, rawNbr int) {
fmt.Println("正在处理", infile)
var id int
start := strings.LastIndexAny(infile, "\\")
id, _ = strconv.Atoi(infile[start+1 : len(infile)-4])
fmt.Println(id)
var cell *xlsx.Cell
var row *xlsx.Row
file, err := os.Open(infile)
if err != nil {
fmt.Println("Failed to open the input file ", infile)
return
}
defer file.Close()
br := bufio.NewReader(file)
var indexi int = 0
_, _, _ = br.ReadLine()
for {
line, isPrefix, err1 := br.ReadLine()
if err1 != nil {
if err1 != io.EOF {
err = err1
}
break
}
if isPrefix {
fmt.Println("A too long line, seems unexpected.")
return
}
str := string(line) // Convert []byte to string
if len(str) < 5 {
break
}
split := str[1 : len(str)-1]
array := strings.Split(split, ",")
row = sheet.AddRow()
cell = row.AddCell()
cell.SetInt(id)
indexi = 0
for _, v := range array {
if indexi >= rawNbr-1 {
break
}
indexi = indexi + 1
cell = row.AddCell()
value, _ := strconv.Atoi(v)
cell.SetInt(value)
}
}
return
}
示例6: Xlsx
// Xlsx writes the day statistics in xlsx format
func (fsd *FlightStatDay) Xlsx(s *xlsx.Sheet) {
r := s.AddRow()
c := r.AddCell()
c.SetDate(fsd.Date)
c.NumFmt = "dd.mm.yyyy"
r.AddCell().SetInt(fsd.Flights)
r.AddCell().SetFloatWithFormat(fsd.Airtime.Minutes(), "0.00")
}
示例7: addRow
func addRow(sheet *xlsx.Sheet, headers ...string) {
row := sheet.AddRow()
for _, header := range headers {
cell := row.AddCell()
cell.Value = header
}
}
示例8: AddCell
//AddCell sheet
func AddCell(sheet *xlsx.Sheet, row, col int) *xlsx.Cell {
// hhh
for row >= len(sheet.Rows) {
sheet.AddRow()
}
for col >= len(sheet.Rows[row].Cells) {
sheet.Rows[row].AddCell()
}
return sheet.Cell(row, col)
}
示例9: getHeader
func getHeader(sheet *xlsx.Sheet) *tool.ExportHeader {
headerString := sheet.Cell(0, 0).Value
var header tool.ExportHeader
if err := proto.UnmarshalText(headerString, &header); err != nil {
return nil
}
return &header
}
示例10: createSheet2
func createSheet2(sheet *xlsx.Sheet) {
r := helpcase.GetAllHelpcaseDetail()
var row *xlsx.Row
var cell *xlsx.Cell
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "編號"
cell = row.AddCell()
cell.Value = "報導標題"
cell = row.AddCell()
cell.Value = "刊登日期"
cell = row.AddCell()
cell.Value = "星期"
cell = row.AddCell()
cell.Value = "按讚數"
cell = row.AddCell()
cell.Value = "段落數"
cell = row.AddCell()
cell.Value = "報導字數"
cell = row.AddCell()
cell.Value = "報導內圖片數"
cell = row.AddCell()
cell.Value = "報導URL"
cell = row.AddCell()
cell.Value = "報導內容全部"
for _, helpcase := range r {
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = helpcase.SerialNo
cell = row.AddCell()
cell.Value = helpcase.Title
cell = row.AddCell()
cell.Value = helpcase.Date
cell = row.AddCell()
cell.SetFormula("weekday(\"" + helpcase.Date + "\",2)")
cell = row.AddCell()
cell.SetInt(helpcase.LikeCount)
cell = row.AddCell()
cell.SetInt(helpcase.ParagraphCount)
cell = row.AddCell()
cell.SetInt(helpcase.WordCount)
cell = row.AddCell()
cell.SetInt(helpcase.ImgCount)
cell = row.AddCell()
cell.SetFormula("HYPERLINK(\"" + helpcase.DetailUrl + "\",\"" + helpcase.DetailUrl + "\")")
cell = row.AddCell()
cell.Value = helpcase.Content
}
}
示例11: TestCheckGetHeader
func (s *UtilTestSuite) TestCheckGetHeader(c *C) {
GetCheckResultHeader()
checkResult := CheckResult{}
var file *xlsx.File
var sheet *xlsx.Sheet
file = xlsx.NewFile()
sheet, _ = file.AddSheet("Sheet1")
sheet.AddRow()
checkResult.WriteToRow(sheet.AddRow())
c.Log(checkResult)
}
示例12: createSheet1
func createSheet1(sheet *xlsx.Sheet) {
r := helpcase.GetAllHelpcase()
var row *xlsx.Row
var cell *xlsx.Cell
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "編號"
cell = row.AddCell()
cell.Value = "報導標題"
cell = row.AddCell()
cell.Value = "刊登日期"
cell = row.AddCell()
cell.Value = "星期"
cell = row.AddCell()
cell.Value = "狀態"
cell = row.AddCell()
cell.Value = "累計(元)"
cell = row.AddCell()
cell.Value = "捐款明細"
font := &xlsx.Font{Color: "blue", Underline: true}
style := xlsx.NewStyle()
style.Font = *font
for _, helpcase := range r {
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = helpcase.SerialNo
cell = row.AddCell()
cell.Value = helpcase.Title
cell = row.AddCell()
cell.Value = helpcase.Date
cell = row.AddCell()
cell.SetFormula("weekday(\"" + helpcase.Date + "\",2)")
cell = row.AddCell()
cell.Value = helpcase.Status
cell = row.AddCell()
cell.SetInt(helpcase.Amount)
cell.NumFmt = "#,##0 ;(#,##0)"
cell = row.AddCell()
cell.SetStyle(style)
cell.SetFormula("HYPERLINK(\"http://search.appledaily.com.tw/charity/projdetail/proj/" + helpcase.SerialNo + "\",\"明細\")")
}
}
示例13: main
func main() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
var err error
file = xlsx.NewFile()
sheet = file.AddSheet("Sheet1")
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "I am a cell!"
err = file.Save("d:/Desktop/demo_write.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}
示例14: subjectGrid
func subjectGrid(sheet *xlsx.Sheet, g group.Group, subj *subject.Subject, natYear string) {
pg := g.ProgressGrid(subj, natYear)
row := sheet.AddRow()
row = sheet.AddRow()
blankCell(row)
newCell(row, "Progress Grid: "+subj.Subj, newStyle("Title", "None", "None", "Left"))
row = sheet.AddRow()
row = sheet.AddRow()
blankCell(row)
newCell(row, "KS2", newStyle("Bold", "None", "Bottom", "Left"))
for _, grd := range pg.Grades {
newCell(row, grd, newStyle("Bold", "None", "Bottom", "Center"))
}
newCell(row, "VA", newStyle("Bold", "None", "Bottom", "Center"))
for i, ks2 := range pg.KS2 {
row := sheet.AddRow()
blankCell(row)
newCell(row, ks2, newStyle("Bold", "None", "None", "Left"))
for j := range pg.Grades {
pgCell := pg.Cells[i][j]
switch {
case pg.CellVA[i][j] < -0.33:
newInt(row, len(pgCell.Students), newStyle("Default", "Red", "None", "Center"))
case pg.CellVA[i][j] > 0.67:
newInt(row, len(pgCell.Students), newStyle("Default", "Green", "None", "Center"))
default:
newInt(row, len(pgCell.Students), newStyle("Default", "Yellow", "None", "Center"))
}
}
newFloat(row, pg.RowVA[i], "+0.00;-0.00;0.00", newStyle("Default", "None", "None", "Center"))
}
row = sheet.AddRow()
blankCell(row)
newCell(row, "Total", newStyle("Bold", "None", "None", "None"))
for i := range pg.Grades {
newInt(row, pg.Counts[i], newStyle("Bold", "None", "None", "Center"))
}
newFloat(row, g.SubjectVA(subj.Subj).VA, "+0.00;-0.00;0.00", newStyle("Bold", "None", "None", "Center"))
}
示例15: test2AddSheet
func test2AddSheet() {
var file *xlsx.File
var sheet *xlsx.Sheet
var row *xlsx.Row
var cell *xlsx.Cell
file, _ = xlsx.OpenFile("MyXLSXFile.xlsx")
sheet = file.AddSheet("addSheet")
row = sheet.AddRow()
cell = row.AddCell()
cell.Value = "addSheet000101"
cell = row.AddCell()
cell.Value = "addSheet中文1"
err := file.Save("MyXLSXFile.xlsx")
if err != nil {
fmt.Printf(err.Error())
}
}