Professional Documents
Culture Documents
import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFDataFormatter; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFFontFormatting; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.util.HSSFColor;
public class CreateExcelFile{ public static void maina(ArrayList a){ try{ System.out.println(a); String s=(String) a.get(0); String s1=(String) a.get(1); String s2=(String) a.get(2);
String s3=(String) a.get(3); String s4=(String) a.get(4); String s5=(String) a.get(5); String s6=(String) a.get(6); String s7=(String) a.get(7); String filename="c:/data.xls" ; HSSFWorkbook hwb=new HSSFWorkbook(); HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFCell cellC1 = rowhead.createCell((short) 2); cellC1.setCellValue(" 35 "); HSSFCell cellD1 = rowhead.createCell((short) 3); cellD1.setCellValue(" 49 "); HSSFCell cellE1 = rowhead.createCell((short) 4); cellE1.setCellValue(" 56 "); HSSFCell cellF1 = rowhead.createCell((short) 5); cellF1.setCellValue(" 34 "); HSSFCell cellG1 = rowhead.createCell((short) 6);
//
Class.forName("com.mysql.jdbc.Driver");
//
ResultSet rs=st.executeQuery("Select * from FIXExcedata"); int i=2; HSSFCellStyle cellStyle2 = hwb.createCellStyle(); cellStyle2.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index); cellStyle2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//
HSSFCell cellA2 = rowhead2.createCell((short) 0); cellA2.setCellValue(s); // cellA2.setCellValue(rs.getString("Symbol")); HSSFCell cellB2 = rowhead2.createCell((short) 1); cellB2.setCellValue(s1); HSSFCell cellC2 = rowhead2.createCell((short) 2); cellC2.setCellValue(s2); HSSFCell cellD2 = rowhead2.createCell((short) 3); cellD2.setCellValue(s3); HSSFCell cellE2 = rowhead2.createCell((short) 4); cellE2.setCellValue(s4); HSSFCell cellF2 = rowhead2.createCell((short) 5); cellF2.setCellValue(s5); HSSFCell cellG2 = rowhead2.createCell((short) 6); cellG2.setCellValue(s6); HSSFCell cellH2 = rowhead2.createCell((short) 7);
cellH2.setCellValue(s7); // if(i%2==0){ cellA2.setCellStyle(cellStyle2); cellB2.setCellStyle(cellStyle2); cellC2.setCellStyle(cellStyle2); cellD2.setCellStyle(cellStyle2); cellE2.setCellStyle(cellStyle2); cellF2.setCellStyle(cellStyle2); cellG2.setCellStyle(cellStyle2); cellH2.setCellStyle(cellStyle2); } i++; // } FileOutputStream fileOut = new FileOutputStream(filename); hwb.write(fileOut); fileOut.close(); System.out.println("Your excel file has been generated!");