基本思路:

1.从附件服务器上取得模板的流文件

2.拿到流文件之后再使用workbook.write(outs);方法改变流文件中的数据。

        else if (pageContext.getParameter("Export") != null) {
OraclePreparedStatement oraclepreparedstatement;
OracleResultSet oracleresultset;
oraclepreparedstatement = null;
oracleresultset = null;
String attachmentId = null; int count = 0;
try {
oraclepreparedstatement =
(OraclePreparedStatement)EditImportDataAM.getOADBTransaction().createPreparedStatement("SELECT COUNT(1)\n" +
" FROM mtl_categories_b_kfv\n" +
" WHERE category_id IN (SELECT category_id FROM cux_pon_categorys WHERE auction_header_id = '"+auctionHeaderId+"')",
1);
oracleresultset = (OracleResultSet)oraclepreparedstatement.executeQuery();
if (oracleresultset.next()) {
count = oracleresultset.getInt(1);
}
} catch (SQLException e) {
}
if(count==0){
throw new OAException("CUX","CUX_CATEGORY_DEMAND_NOT_NULL",null,OAException.ERROR,null);
} try {
oraclepreparedstatement =
(OraclePreparedStatement)EditImportDataAM.getOADBTransaction().createPreparedStatement(" select cat.id from cux_attachment_t cat where cat.source_type='PON' and cat.source_table = 'PON_AUCTION_ITEM_TEMPLETE' and cat.source_id='-99999' and cat.file_status = 'C'",
1);
oraclepreparedstatement.defineColumnType(1, -5);
oracleresultset =
(OracleResultSet)oraclepreparedstatement.executeQuery();
if (oracleresultset.next()) {
attachmentId =
(new StringBuilder()).append("").append(oracleresultset.getLong(1)).toString();
} else {
throw new OAException("不存在定价行导入模板");
}
} catch (Exception exception2) {
throw OAException.wrapperException(exception2);
} LogUtil.of(attachmentId, pageContext).print(pageContext);
downloadFileFromServer(pageContext, webBean, attachmentId);
// exportModeExcel(pageContext, webBean, attachmentId);
return;
} public void downloadFileFromServer(OAPageContext pageContext,
OAWebBean webBean,
String attachmentId) {
OAApplicationModule am = pageContext.getApplicationModule(webBean);
AttachementVOImpl AttachementVO =
(AttachementVOImpl)am.findViewObject("AttachementVO");
if (AttachementVO == null) {
AttachementVO =
(AttachementVOImpl)am.createViewObject("AttachementVO",
"cux.oracle.apps.cux.attachement.server.AttachementVO");
}
AttachementVO.setWhereClause(null);
AttachementVO.setWhereClauseParams(null);
String sql = "1=1 and ID='" + attachmentId + "'";
AttachementVO.setWhereClause(sql);
AttachementVO.setMaxFetchSize(-1);
AttachementVO.executeQuery();
AttachementVORowImpl attachementInfo =
(AttachementVORowImpl)AttachementVO.first();
HttpServletResponse response =
(HttpServletResponse)pageContext.getRenderingContext().getServletResponse();
String fileType =
attachementInfo.getFileMimetype();
response.setContentType(fileType); String fileName = attachementInfo.getFileName();
try {
response.addHeader("Content-Disposition",
"attachment;filename=" + new String(fileName.getBytes("GBK"),
"ISO-8859-1"));
response.setHeader("Content-Transfer-Encoding", "binary");
// response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragma", "public");
} catch (UnsupportedEncodingException e) { LogUtil.of("downloadFileFromServer from FTP server Error-filename!",
this);
} InputStream in = null;
ServletOutputStream outs = null; FtpUtil ftp = this.getFtp(pageContext); try {
outs = response.getOutputStream();
//获取附件流文件
in = ftp.getFile(attachementInfo.getFilePath(), attachementInfo.getFileName()); // int ch;
// while ((ch = in.read()) != -1) {
// outs.write(ch);
// } // Workbook workbook = new XSSFWorkbook(in);
// org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(1);
// org.apache.poi.ss.usermodel.Row row = null;
// org.apache.poi.ss.usermodel.Cell cell = null;
//
// String cellValue = "132700002800";
//
// for (int i = 0; i < 5; i++) {
// System.out.println(" i =" + i);
// row = sheet.createRow(i);
// cell = row.createCell(0);
// cell.setCellValue(cellValue);
// }
// workbook.write(outs); exportExcel(pageContext,in, outs); } catch (IOException e) {
LogUtil.of("downloadFileFromServer from FTP server Error-!" +
e.getMessage(), this);
} finally {
try {
outs.flush();
outs.close();
if (in != null) {
in.close();
}
ftp.closeClient();
} catch (Exception e) {
e.printStackTrace();
}
}
} /**
* 获取FTP配制信息,并初始化连接
* @param pageContext
* @return
*/
protected FtpUtil getFtp(OAPageContext pageContext) {
String host = pageContext.getProfile("CUX_SRM_FTP_HOST");
String port = pageContext.getProfile("CUX_SRM_FTP_PORT");
String user = pageContext.getProfile("CUX_SRM_FTP_USER");
String password = pageContext.getProfile("CUX_SRM_FTP_PASSWORD");
return new FtpUtil(host, port, user, password);
} public void exportExcel(OAPageContext pageContext,InputStream ins,OutputStream outs){ try {
OAApplicationModule am = pageContext.getRootApplicationModule();
OAApplicationModule EditImportDataAM = null;
EditImportDataAM =
(OAApplicationModule)am.findApplicationModule("EditImportDataAM"); OAViewObject AuctionHeadersAllVO =
(OAViewObject)am.findViewObject("AuctionHeadersAllVO");
AuctionHeadersAllVORowImpl AuctionHeadersAllRow =
(AuctionHeadersAllVORowImpl)AuctionHeadersAllVO.first();
Number auctionHeaderId = AuctionHeadersAllRow.getAuctionHeaderId(); OAViewObject itemSegVO =
(OAViewObject)EditImportDataAM.findViewObject("CuxAucItemSegmentsVO1");
itemSegVO.setWhereClause(null);
itemSegVO.setWhereClauseParams(null);
itemSegVO.setWhereClauseParam(0, auctionHeaderId);
itemSegVO.executeQuery(); RowSetIterator itemSegIter =
itemSegVO.findRowSetIterator("itemSegIter") == null ?
itemSegVO.createRowSetIterator("itemSegIter") :
itemSegVO.findRowSetIterator("itemSegIter"); Row itemSegRow = null;
int itemSegCount = itemSegVO.getRowCount(); Workbook workbook = new XSSFWorkbook(ins);
org.apache.poi.ss.usermodel.Sheet sheet = workbook.getSheetAt(1); org.apache.poi.ss.usermodel.Row row = null;
org.apache.poi.ss.usermodel.Cell cell = null; if (itemSegCount > 0) {
itemSegIter.setRangeStart(0);
itemSegIter.setRangeSize(itemSegCount);
for (int i = 0; i < itemSegCount; i++) {
itemSegRow = itemSegIter.getRowAtRangeIndex(i);
String itemDescription =
(String)itemSegRow.getAttribute("Description");
String itemNumber =
(String)itemSegRow.getAttribute("ItemNumber");
row = sheet.createRow(i);
cell = row.createCell(0);
cell.setCellValue(itemDescription);
cell = row.createCell(1);
cell.setCellValue(itemNumber);
}
}
itemSegIter.closeRowSetIterator(); workbook.write(outs);
}catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
outs.flush();
outs.close();
if (ins != null) {
ins.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

使用POI动态更新导出的EXCEL模板中的列的更多相关文章

  1. C# 导出数据到Excel模板中(转)

    今天做报表的时候遇到了多表头的问题,而且相应的报表的格式都一样.所以就采用了报表模板的方式来进行. 第一步:在开发的当前项目中引入:Microsoft.Office.Interop.Excel:Sys ...

  2. 替换excel模板中的内容并使用JavaMail发送邮件

    由于在公司工作,常年出差,每天都要以日报的形式向公司汇报当天的工作内容.而日报的内容大体上就只有当天工作的主要内容时变化的,其余的都是不变 的. 而我的电脑刚打开excel有点卡,因此决定使用Java ...

  3. 动态更新Toolbar Menu以及Menu中同时显示文字和图标

    动态更新Toolbar Menu以及Menu中同时显示文字和图标 我们经常会有这样的需求,在切换Fragment或者点击某个按钮后动态更新Toolbar上Menu项.但是onCreateOptions ...

  4. JAVA POI替换EXCEL模板中自定义标签(XLSX版本)满足替换多个SHEET中自定义标签

    个人说明:为了简单实现导出数据较少的EXCEL(根据自定义书签模板) 一.替换Excel表格标签方法```/** * 替换Excel模板文件内容 * @param map * 需要替换的标签建筑队形式 ...

  5. SSIS 中将csv 文件批量导出到excel 文件,并设置excel 文件中某些列的data column format 为Text

    csv 文件是文本文件类型,但是打开csv 文件后(默认使用本地已经安装的excel 来打开excel 文件),默认显示出来的是general 类型(column data format)的数据, 这 ...

  6. java中的数据导出到Excel表中

    整个项目中导出数据到.Excel的源码 import java.io.BufferedOutputStream; import java.io.FileInputStream; import java ...

  7. PHP 导出到Excel表格中

    /** * 导出excel * @throws \PHPExcel_Exception * @throws \PHPExcel_Reader_Exception * @throws \PHPExcel ...

  8. 从数据库的表导出到Excel表格中【让客户端下载的Excel】

    原文发布时间为:2008-10-11 -- 来源于本人的百度文章 [由搬家工具导入] 这个例子是从gridview中导出到Excel,可以举一反三,可以直接从数据库中取值放在DataSet中,然后再从 ...

  9. 使用python读取京东pdf发票信息导出到excel表格中

    代码 #!/usr/bin/env python # -*- coding: utf-8 -*- """ pip install pdfminer3k pip insta ...

随机推荐

  1. Java编程思想第四版勘误

    坊间传说这本书翻译得很烂,我倒觉得还好.虽然看原文更准确,但是如果在具备一定编程思维和基础.能够看出来疑问的情况下,还是看中文更快一些,而且这本书本身也不适合初学者看.当然,错误和不通顺还是有的,而且 ...

  2. ora-00600错误解决一枚

    今天网友遇到ora-600错误,这里把这个ora-600错误的解决方法详细记录一下. 最初报错信息如下: ora-600-图1 ora-600-图2 图3 这里我们可以看到报错控制文件版本不一致,要求 ...

  3. Scrapy框架(3)

    一.如何提升scrapy框架的爬取效率 增加并发: 默认scrapy开启的并发线程为32个,可以适当进行增加.在settings配置文件中修改CONCURRENT_REQUESTS = 100,并发设 ...

  4. day11(jsp入门&Cookie&HttpSession&一次性图片校验码)

    day11 JSP入门   1 JSP概述 1.1 什么是JSP JSP(Java Server Pages)是JavaWeb服务器端的动态资源.它与html页面的作用是相同的,显示数据和获取数据. ...

  5. mysql 数据操作 单表查询 group by 分组 目录

    mysql 数据操作 单表查询 group by 介绍 mysql 数据操作 单表查询 group by 聚合函数 mysql 数据操作 单表查询 group by 聚合函数 没有group by情况 ...

  6. HDFS的Java API

    HDFS Java API 可以用于任何Java程序与HDFS交互,该API使我们能够从其他Java程序中利用到存储在HDFS中的数据,也能够使用其他非Hadoop的计算框架处理该数据 为了以编程方式 ...

  7. php array_map array_filter sort

    array_map — Applies the callback to the elements of the given arrays (处理映射) array_filter — Filters e ...

  8. idea使用插件activate-power-mode给编码加上特效和带来乐趣。

    一.安装. 1. 2. 二.使用. 1. 2.

  9. 2018年浙江中医药大学程序设计竞赛 Solution

    Problem A. Jhadgre的C语言程序 签. #include <bits/stdc++.h> using namespace std; int main() { puts(&q ...

  10. Python tricks(1) -- 动态定义一个新变量

    python是动态语言, 无需声明变量即可使用. 传递一个tuple, list或者dict等等方式, 有时候这种方式的使用不是很好. 对于tuple和list来说都是用下标的访问方式(即使用[]), ...