I am trying a script to read content of an issue attachment. The script works for CSV and TXT types, but does not work for XLSX or XLS type.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.Attachment
import com.atlassian.jira.issue.attachment.FileAttachments
import com.atlassian.jira.util.AttachmentUtils
import org.apache.commons.io.FilenameUtils
import com.atlassian.jira.util.io.InputStreamConsumer
import org.springframework.util.StreamUtils
import java.io.FileOutputStream
import java.io.InputStream
import java.io.IOException
import groovy.util.XmlParser
import groovy.util.XmlSlurper
import com.atlassian.jira.*
def issueManager = ComponentAccessor.getIssueManager()
def aM= ComponentAccessor.getAttachmentManager()
def pM = ComponentAccessor.getAttachmentPathManager()
def attachments = aM.getAttachments(issue)
String attachmentFileText=""
if (!attachments.isEmpty()) {
for (Attachment a in attachments) {
def fileName=FilenameUtils.getBaseName(a.getFilename())
log.warn (fileName)
def fileExtension=FilenameUtils.getExtension(a.getFilename())
log.warn (fileExtension)
def attachmentFile = aM.streamAttachmentContent(a, new FileInputStreamConsumer(a.getFilename()))
log.warn("This is attachmentFile" + attachmentFile)
List attachmentFileLines = attachmentFile.text.split('\n')
def righeFile=1
log.warn("This is attachmentFileLines" + attachmentFileLines)
attachmentFileLines.each(){
singleLine->
attachmentFileText=attachmentFileText+singleLine
righeFile=righeFile+1
}
return attachmentFileLines
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.