Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

streamAttachmentContent does not work for Excel attachment

ABRAR ALI November 23, 2022

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
}
}

1 answer

0 votes
ABRAR ALI November 24, 2022

@Boris Georgiev {Appfire}  @Ravi Sagar _Sparxsys_ @Nic Brough -Adaptavist- 

Will you be able to help me resolve this. 
I am setting this script in a scripted field and it is returning values for CSV and TXT files. Excel files seems to give a non-human readable format. I don't know how to convert it.

-Abrar

Suggest an answer

Log in or Sign up to answer