Structure (DC)
Breadcrumbs

Export to Excel Using ScriptRunner

This script can be used in ScriptRunner to export data in an Excel-compatible format. Use ScriptRunner Jobs to add scheduling.

Export to excel

Groovy
import com.atlassian.jira.component.ComponentAccessor
String fileName = 'filename.xls'
String userName = 'admin'
Long structureId = 1L
// Takes priority over viewSpec that follows.
Long viewId = 8L
// String containing JSON, might be taken literally from the export POST request if put in 'single quotes'.
String viewSpec = null
String expandState = null
String clientFilter = null
def plugin = ComponentAccessor.pluginAccessor.getPlugin('com.almworks.jira.structure')
def helper = plugin.getModuleDescriptor('helper').module
def ExcelExporter = plugin.classLoader.loadClass('com.almworks.jira.structure.export.excel.ExcelExporter')
def exporter = helper.instantiate(ExcelExporter)

def ForestSpec = plugin.classLoader.loadClass('com.almworks.jira.structure.api.forest.ForestSpec')
def spec = ForestSpec.structure(structureId, helper.getUserManager().getUserByKey(userName))
exporter.configure(viewId, viewSpec, spec, expandState, clientFilter)
exporter.prepareExport()
exporter.createWorkbook({null})

def stream = new FileOutputStream(fileName)
try {
exporter.writeWorkbookTo(stream)
} finally {
stream.close()
return new File(fileName).toPath().toAbsolutePath()
}