javajagan
Newbie

Posts: 1
|
 |
« on: May 23, 2008, 05:38:55 AM » |
|
Hi.. Buddies!
I stuck in a problem as below:
I am using struts2 with tomcat6.0.1in netbeans 6.1 with jdk1.6 and ApachePOI.
User has to view data in tabular format based on a search criteria and can download the viewing table of the jsp page in excel sheet to his/her system.
So I am creating excel sheet when the user presses view button . the code gets executed inside ActionForm class itself.
My method to create excelsheet is: ===============================================================
private void createExcel(String filename,String[] rowdata, String[] column) { try { System.out.println("create excel file is called kbfksdjsdjksdfjsdfjsdfjsdjsdfsj");
File file=new File(filename); filepath=file.getCanonicalPath(); java.io.BufferedInputStream in=new java.io.BufferedInputStream((new java.net.URL("Aak_project/Downloads/brandnewExcelfile.xls").openStream())); java.io.FileOutputStream fos = new java.io.FileOutputStream("Aak_project/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); System.out.println("coming to writeDataSheet"+headers);
} //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.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.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++; }
} }
}
look at the bold lines. The file should create there and I can also give an anchor tag containing the above path so that the user can able to download from there.
As it’s not creating there neither I am able to provide the anchor tag path., nor I can give the absolute path in the anchor tag as C:\program files\tomcat\bin because fire fox is telling it’s not a valid protocol... Implicitly my excelfile resides inside ...\tomcat\bin.
I am stuck here.Pls have a reply if you have faced the same or have a solution for it.
Hope the above description will help to understand my problem and to solve it.
Thanks for any anticipation. jagan
|