-
-
Notifications
You must be signed in to change notification settings - Fork 6k
add button to export issues to Excel #35313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package export | ||
|
||
import ( | ||
"fmt" | ||
Check failure on line 7 in services/export/excel.go
|
||
"github.com/xuri/excelize/v2" | ||
|
||
issues_model "code.gitea.io/gitea/models/issues" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
func IssuesToExcel(ctx *context.Context, issues issues_model.IssueList) *excelize.File { | ||
f := excelize.NewFile() | ||
sheet := f.GetSheetName(f.GetActiveSheetIndex()) | ||
|
||
headers := []string{"ID", "Title", "Status", "Assignee(s)", "Label(s)", "Created At"} | ||
for col, h := range headers { | ||
cell, _ := excelize.CoordinatesToCellName(col+1, 1) | ||
f.SetCellValue(sheet, cell, h) | ||
Check failure on line 21 in services/export/excel.go
|
||
} | ||
|
||
for i, issue := range issues { | ||
Check failure on line 24 in services/export/excel.go
|
||
|
||
assignees := "" | ||
if err := issue.LoadAssignees(ctx); err == nil { | ||
if len(issue.Assignees) > 0 { | ||
for _, assignee := range issue.Assignees { | ||
if assignees != "" { | ||
assignees += ", " | ||
} | ||
if assignee.FullName != "" { | ||
assignees += assignee.FullName | ||
} else { | ||
assignees += assignee.Name | ||
} | ||
} | ||
} | ||
} | ||
|
||
labels := "" | ||
if err := issue.LoadLabels(ctx); err == nil { | ||
if len(issue.Labels) > 0 { | ||
for _, label := range issue.Labels { | ||
if labels != "" { | ||
labels += ", " | ||
} | ||
labels += label.Name | ||
} | ||
} | ||
} | ||
|
||
f.SetCellValue(sheet, fmt.Sprintf("A%d", i+2), issue.Index) | ||
Check failure on line 54 in services/export/excel.go
|
||
f.SetCellValue(sheet, fmt.Sprintf("B%d", i+2), issue.Title) | ||
Check failure on line 55 in services/export/excel.go
|
||
f.SetCellValue(sheet, fmt.Sprintf("C%d", i+2), issue.State()) | ||
Check failure on line 56 in services/export/excel.go
|
||
f.SetCellValue(sheet, fmt.Sprintf("D%d", i+2), assignees) | ||
Check failure on line 57 in services/export/excel.go
|
||
f.SetCellValue(sheet, fmt.Sprintf("E%d", i+2), labels) | ||
Check failure on line 58 in services/export/excel.go
|
||
f.SetCellValue(sheet, fmt.Sprintf("F%d", i+2), issue.CreatedUnix.AsTime()) // .Format("2006-01-02")) | ||
Check failure on line 59 in services/export/excel.go
|
||
} | ||
return f | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: https://xuri.me/excelize/en/stream.html
Streaming write should be used here, as ordinary write will occupy a lot of memory when the data volume is slightly larger.