# Get the Excel output file stream byte after calling pxGenerateExcelFile activity

**URL:** <https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452>\
**Category:** General\
**Tags:** email, cross-industry, 8-8-2, lead-system-architect, case-management\
**Created:** [May 11, 2023, 12:38pm UTC](https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452 "2023-05-11T12:38:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Cho](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/will_cho/32/23260_2.png) [@Will\_Cho](https://forums.pega.com/u/Will_Cho)\
**Post date:** [May 11, 2023, 12:38pm UTC](https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452/1 "2023-05-11T12:38:17Z")

</div>

We have successfully generated an Excel output file using pxGenerateExcelFile activity.

Now, how/where can we get the **file content stream**?

We have to attach the output file to an email and send. No work object is involved.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Will\_Cho](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/will_cho/32/23260_2.png) [@Will\_Cho](https://forums.pega.com/u/Will_Cho)\
**Post date:** [May 11, 2023, 7:55pm UTC](https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452/2 "2023-05-11T19:55:23Z")

</div>

@Will Cho I used this Java code to get the byte stream of excel file generated.

Video reference - [https://www.youtube.com/watch?v=w1IYdF8o17E](https://www.youtube.com/watch?v=w1IYdF8o17E)

String strFileName = tools.getParamValue(“OutputLocation”);  
PRFile objFile = new PRFile(strFileName);

//some error checking  
if (!objFile.exists())  
{  
attach = false;  
}

if(!objFile.isFile())  
{  
attach = false;  
}

tools.putParamValue(“OutputLocation”, objFile.getName());

if (!objFile.canRead())  
{  
attach = false;  
throw new PRRuntimeException(“Can’t continue with file upload. File "” + strFileName + “" is unreadable.”);  
}

//read the file into a buffer.  
java.io.DataInputStream dis = null;  
byte buffer = null;

try  
{  
dis = new java.io.DataInputStream(new PRInputStream(objFile));  
buffer= new byte[dis.available()];  
dis.readFully(buffer);  
dis.close();  
}  
catch (Exception e)  
{  
attach = false;  
throw new PRRuntimeException(“Can’t continue with file upload. Can’t read File "” + strFileName + “"”);  
}

//encode the file to Base64 so that we can store it on the database  
strFileData = Base64Util.encodeToString(buffer);

if (strFileData == null)  
{  
attach = false;  
throw new PRRuntimeException(“Can’t continue with file upload. Couldn’t encode the file to Base64 so that we can store it on the database”);  
}

Email sent successful:

 ![Email sent.png](https://pega1.discourse-cdn.com/pega/original/2X/4/492ee793130351e21d79680a789f46c1654c1c26.png)

---

<div class="post-metadata">

**Author:** ![Anoop\_Krishna](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/anoop_krishna/32/23458_2.png) [@Anoop\_Krishna](https://forums.pega.com/u/Anoop_Krishna)\
**Post date:** [May 12, 2023, 3:01am UTC](https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452/3 "2023-05-12T03:01:40Z")

</div>

@Will Cho can you please let me know how you have attached this file to the email? The OOTB activities ask for attachment category and based on category attachments from the case will get attached to the email being sent. Here in your scenario I think you don’t have case, so attaching the attachments after converting it from stream, that process can you let me know?

---

<div class="post-metadata">

**Author:** ![Will\_Cho](https://yyz2.discourse-cdn.com/pega/user_avatar/forums.pega.com/will_cho/32/23260_2.png) [@Will\_Cho](https://forums.pega.com/u/Will_Cho)\
**Post date:** [October 6, 2026, 12:15pm UTC](https://forums.pega.com/t/get-the-excel-output-file-stream-byte-after-calling-pxgenerateexcelfile-activity/4452/4 "2026-10-06T12:15:00Z")

</div>

Sorry i missed your question long time ago. Here is how to attach the Excel file to email.

> [@How to attach Excel file to email](https://forums.pega.com/t/how-to-attach-excel-file-to-email/4897):
>
> This article shows step-by-step configurations of exporting a data page list to an Excel file and then sending the Excel file as an email attachment. This demo was initially developed using Pega Platform 8.8.2 and later updated to 23.1.1. Here is a high-level view of the activity. See the details of each step below. Step 1 – Set an output Excel file name. Notice the file extension (.xlsx) used. Step 2 – Generate an Excel file by using an OOTB pxGenerateExcel…
