<%@ page import="java.io.File"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileNotFoundException"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="org.apache.poi.ss.usermodel.*"%>
<%
try
{
FTPHOST = <FTPHOST>;
FTPUName = <FTP USERNAME>;
FTPPwd = <FTP PASSWORD>;
FileInputStream fis = new FileInputStream(new File(getServletContext().getRealPath("/")+"/Templates/template.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(fis);
CellStyle style = workbook.createCellStyle();
// style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
// style.setFillPattern(CellStyle.SOLID_FOREGROUND);
//style.setBorderLeft(CellStyle.BORDER_THIN);
// style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
// style.setBorderRight(CellStyle.BORDER_THIN);
// style.setRightBorderColor(IndexedColors.BLACK.getIndex());
// style.setBorderTop(CellStyle.BORDER_THIN);
// style.setTopBorderColor(IndexedColors.BLACK.getIndex());
// style.setBorderBottom(CellStyle.BORDER_THIN);
// style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setAlignment(CellStyle.ALIGN_JUSTIFY);
HSSFSheet sheet = workbook.getSheetAt(0);
Cell cell = null;
cell = sheet.getRow(5).getCell(5);
cell.setCellValue(insuredname);
cell = sheet.getRow(5).getCell(9);
cell.setCellValue(ptname);
cell = sheet.getRow(5).getCell(13);
cell.setCellValue(age+"/"+sex);
cell = sheet.getRow(5).getCell(16);
cell.setCellValue(relation);
cell = sheet.getRow(5).getCell(20);
cell.setCellValue(balsi);
cell.setCellStyle(style);
filePath = "FTPPATH/.xls";
URL url = new URL("ftp://"+FTPUName+":"+FTPPwd+"@"+FTPHOST+"/"+filePath);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.connect();
OutputStream out1 = conn.getOutputStream();
workbook.write(out1);
out1.close();
fis.close();
}
catch(Exception e)
{
System.out.println("EXCEPTION :"+e);
}//catch
No comments:
Post a Comment