|
using struts2 with tomcat6.0.1in netbeans 6.1 with jdk1.6 Problem: Giving a relative path fire fox is telling it’s not a valid protocol
Method to create excelsheet is: =============================================================== private void createExcel(String filename,String[] rowdata, String[] column) { try { System.out.println("create excel file is called Emp_Data");
File file=new File(filename); filepath=file.getCanonicalPath(); //file path should return some base address java.io.BufferedInputStream in=new java.io.BufferedInputStream((new java.net.URL("file:///Downloads/brandnewExcelfile.xls").openStream())); //relative path problem java.io.FileOutputStream fos = new java.io.FileOutputStream("file:///Downloads/brandnewExcelfile.xls "); java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
System.out.println("path of the file is"+filepath);
WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale("en", "EN")); WritableWorkbook workbook =Workbook.createWorkbook(file, ws); WritableSheet s = workbook.createSheet("completesheet", 0); writeDataSheet(s,rowdata,column); workbook.write(); workbook.close();
} catch (IOException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } }
private static void writeDataSheet(WritableSheet s,String[] rowdata,String[] headers) throws WriteException { System.out.println("coming to writeDataSheet"); for(int i=0;i<headers.length;i++){ System.out.println("coming to writeDataSheet"+rowdata[i]); System.out.println("coming to writeDataSheet"+headers[i]);
} //get the no of columns System.out.println("length of header is"+headers.length); System.out.println("length of row is"+rowdata.length); for (int i=0;i<rowdata.length;i++){ System.out.println(rowdata[i].toString()); } int nc=headers.length; int rows=rowdata.length/nc; /* Format the Font */
WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD); WritableCellFormat cf = new WritableCellFormat(wf); cf.setWrap(true); Label l ;
/* Creates Label and writes date to first row of sheet*/ for(int i=0;i<headers.length;i++){ l = new Label(i, 0,headers[i].toString() , cf); s.addCell(l); } int k=0;
for(int j=1;j<rowdata.length/7;j++){ for(int m=0;m<7;m++){ l = new Label(m,j,rowdata[k].toString()); System.out.print(k+"harekrishna"+rowdata[k].toString()); s.addCell(l); if(k<(rowdata.length-1)){ k++; }
} } }
Labels: JAVA
0 Comments & Related Links:
Post / Read Comments
Back to Home
----------------------------------------------------------------------------------------------------------------------------------
|