首页 > 其他分享 >OAF export data from VO in xlsx format

OAF export data from VO in xlsx format

时间:2024-08-01 18:41:08浏览次数:14  
标签:OAF xlsx Create format pageContext oracle import response row

In this article we are going to see how to export view object in Microsoft office excel xlsx format

To export with xlsx format few basic things needed are
Jar files (List of jar i've used is shown in below screen shot)

For better understanding I’ll illustrated steps to follow.

Sample Workspace and the jar files can be downloaded at the end of the article

Steps to create data module to be used in the page:

a. Create table
create table suren_employee (emplno number, empl_name varchar2(100),LAST_UPDATE_DATE DATE,LAST_UPDATED_BY NUMBER (15),LAST_UPDATE_LOGIN NUMBER (15),CREATION_DATE DATE,CREATED_BY NUMBER (15));

b. Insert data to table
insert into suren_employee (emplno,empl_name) values (10, 'SURENDRANATH');
insert into suren_employee (emplno,empl_name) values (20, 'SUBRAMANI');

Steps to design the page:
Create project
Create EO
Create VO
Create application module
Create page
Assign AM to the page
Create a item with style as ‘exportButton’
Set controller on the page layout
Create button in the page layout

After following above steps your project should look like this

Copy paste below code in the controller:

/* This is a sample code which should be used in the controller
writeXLSXFile is the method which will export data
Call writeXLSXFile method in the PFR (Process Form Request)
*/

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAViewObject;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import suren.oracle.apps.ak.server.SurenEmployeeVORowImpl;
import oracle.jbo.domain.Number ;

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
if(pageContext.getParameter("Download")!=null)
{
try{
System.out.println("Before writeXLSXFile");
writeXLSXFile(pageContext, "SurenEmployeeVO1");
System.out.println("After writeXLSXFile");
}catch(IOException e){
e.printStackTrace();
}

                }  

}

public void writeXLSXFile(OAPageContext pageContext,String view_inst_name) throws IOException {

OAViewObject vo = (OAViewObject) pageContext.getRootApplicationModule().findViewObject(view_inst_name);           
String sheetName = "Export code comb";//name of sheet
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();

// Set excel property

response.setHeader("Header-Name", "Codecombination");
response.setHeader("Content-Length", "100000");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition","attachment; filename=" + "SurenEmp" + ".xlsx");
response.setHeader("Cache-Control","max-age=0");

XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(sheetName);

// Create header

XSSFRow row12 = sheet.createRow(0);

    XSSFCell celh0 = row12.createCell(0);
    celh0.setCellValue("Employee Number");      
    XSSFCell celh1 = row12.createCell(1);
    celh1.setCellValue("Employee Name");        

int f=1;
    for(SurenEmployeeVORowImpl row = (SurenEmployeeVORowImpl) vo.first(); row != null;row = (SurenEmployeeVORowImpl) vo.next())
{
// Create line
    XSSFRow row1 = sheet.createRow(f);

             for (int i = 0; i < vo.getAttributeCount(); i++)
             {
                     
                     if (i==0) {
                     XSSFCell cell = row1.createCell(i);
                     Number empno = (Number)row.getEmplno();
                     String empno1=empno.toString();

                       cell.setCellValue(empno1);
                      System.out.println(row.getEmplno());
                     }
                     if (i==1) {
                     XSSFCell cell = row1.createCell(i);
                     cell.setCellValue(row.getEmplName());    // Dept
                     }
               }
    System.out.println("row2:" + f);
    f=f+1;
}



ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
wb.write(outByteStream);
byte[] outArray = outByteStream.toByteArray();
response.setContentLength(outArray.length);
ServletOutputStream outStream = response.getOutputStream();
outStream.write(outArray);
outStream.flush();
outStream.close();

}

You will see errors in the controller saying missing “XSSFCell not found” etc.
To fix this go to your project property and add poi library to the project.

标签:OAF,xlsx,Create,format,pageContext,oracle,import,response,row
From: https://www.cnblogs.com/ethanwan/p/18337245

相关文章

  • WebApi连接数据库报错:尝试加载Oracle客户端时引发BadImageFormatException
    出现的问题  今天在公司用C#搭建一个WebApi服务,接受请求并连接数据库进行查询,但连接数据库时报错:尝试加载Oracle客户端时引发BadImageFormatException。如果安装32位客户端组件的情况下以64位模式运行,将出现此问题。问题点  我之后了解点,确定了OracleClient客户端确实安装......
  • NIS(Network Information Services)服务端在R系部署,客户端rpm,deb简单使用
    #!/bin/bash####@Author:[email protected]#@Date:2024-05-28#@LastEditors:[email protected]#@LastEditTime:2024-07-19#@FilePath:NIS-use.sh#@Description:NIS(NetworkInformationServices)source:https://www.th......
  • 使用 Python 读取 .xlsx 文件的最快方法
    我正在尝试使用Python将.xlsx文件中的数据读入MySQL数据库。这是我的代码:wb=openpyxl.load_workbook(filename="file",read_only=True)ws=wb['MyWorksheet']conn=MySQLdb.connect()cursor=conn.cursor()cursor.execute("SETautocommit=0"......
  • Vue3 - 最新详细实现网站内部打开预览 office 全套附件,在页面弹窗内解析预览 word文档
    前言如果您需要Vue2版本,请访问这篇文章。在vue3|nuxt3项目开发中,详解实现项目内部“打开解析预览各种office文档”通用预览插件,支持弹出一个窗口在弹框内预览或者直接显示在页面某个div容器里面,解析预览word文档、excel电子表格、ppt演示文稿、pdf文档、txt文......
  • Vue2 - 最新详细实现网站内部打开预览 office 全套附件,在页面弹窗内解析预览 word文档
    前言如果您需要Vue3版本,请访问在vue2|nuxt2项目开发中,详解实现项目内部“打开解析预览各种office文档”通用预览插件,解析预览word文档、excel电子表格、ppt演示文稿、pdf文档、txt文本等,支持弹出一个窗口在弹框内预览或者直接显示在页面某个div容器里面,让vue项......
  • num_format 不适用于 Excel 列
    希望有人能对此有所了解,因为今天到目前为止,这已经打败了我。上下文:我有一个通过pandasstyler设计的pandas数据框,我通过文件对话导出该数据框,以便可以使用tkinter通过Windows文件对话GUI输入正确的扩展名的文件名。在导出过程中,我使用xlsxwriter格式化列宽并......
  • DatetimeFormatter字符串转日期
    在Java中,我们经常需要将字符串形式的日期时间转换为LocalDateTime、LocalDate、LocalTime等日期时间对象,或者将日期时间对象转换为字符串。为了完成这些操作,我们可以使用DateTimeFormatter类。1.导入必要的类首先,确保你已经导入了必要的类:importjava.time.LocalDateTime;......
  • 06_Calendar类_SimpleDateFormat类_System类
    一、Calendar类Calendar的构造方法是protectedCalendar(),由于修饰符是protected,所以无法直接创建该对象,需要使用Calendar.getInstance();创建。其他方法:代码示例:importjava.util.Calendar;publicclassdemo01{publicstaticvoidmain(String[]args){......
  • SQL注入基础之information_schema
    1.information_schema概述在SQL注入攻击中,information_schema数据库是MySQL自带的一个特殊数据库,它提供了访问数据库元数据的方式。元数据是关于数据的数据,如数据库名、表名、列的数据类型、访问权限等。2.information_schema中的常用表1.schemate描述:提供了当前MySQL实例......
  • Java使用xlsx-streamer和EasyExcel解决读取超大excel文件数据处理方法
    前言最近有个项目在生产环境做数据导入时,发现开始执行导入任务会出现cpu狂飙的情况。几番定位查找发现是在读取excel的时候导致此问题的发生,因此在通常使用的为POI的普通读取,在遇到大数据量excel,50MB大小或数五十万行的级别的数据容易导致读取时内存溢出或者cpu飙升。需要注意,本......