基本思路:

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参数没有引用传递,只有值传递

    原文章地址:http://www.cnblogs.com/clara/archive/2011/09/17/2179493.html 当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性, ...

  2. Day20 javaWeb监听器和国际化

    day20 JavaWeb监听器 三大组件: Servlet Listener Filter   Listener:监听器 初次相见:AWT 二次相见:SAX   监听器: 它是一个接口,内容由我们来 ...

  3. RedHat 6.6下安装nginx,配置HTTPS

    1.安装依赖包 yum -y install pcre-devel openssl-devel zlib-devel 2.下载nginx安装包到服务器上,当前使用版本nginx-1.15.5.tar. ...

  4. mysql 数据操作 多表查询 子查询 带EXISTS关键字的子查询

    带EXISTS关键字的子查询 EXISTS关字键字表示存在. EXISTS 判断某个sql语句的有没有查到结果 有就返回真  true 否则返回假 False 如果条件成立 返回另外一条sql语句的返 ...

  5. Struts2表单数据接收方式

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sunshoupo211/article/details/30249239 1.将Action类作 ...

  6. IQKeyboardManager第三方库的使用

    IQKeyboardManager是iOS中解决键盘弹起遮挡UITextField/UITextView的一种很实用的工具.无需输入任何代码,不需要额外的设置.使用IQKeyboardManager的 ...

  7. SqlServer PIVOT函数快速实现行转列,UNPIVOT实现列转行(转)

    我们在写Sql语句的时候没经常会遇到将查询结果行转列,列转行的需求,拼接sql字符串,然后使用sp_executesql执行sql字符串是比较常规的一种做法.但是这样做实现起来非常复杂,而在SqlSe ...

  8. PHP指定概率算法

    转载来源链接: https://blog.csdn.net/sinat_35861727/article/details/54980807 PHP指定概率算法,可用于刮刮卡,大转盘等抽奖算法. 假设: ...

  9. [sql] 同库表(结构)的备份和sql聚合&navicat使用

    同库表的备份-赋值表结构和数据SQL语句 参考 有时候我们处理某个表时,需要先备份下这个表到当前这个库,然后再执行sql. 站在sql角度,就无需在mysqldump或者诸如导出sql的方式来备份了. ...

  10. 概率图模型PFM——无向图

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdYAAAFPCAIAAAB/EXiGAAAgAElEQVR4nO2df4wl1XXn6/+0VuG/II ...