Code
1import java.io.File;
2import java.io.FileInputStream;
3import java.io.FileOutputStream;
4import java.io.InputStream;
5
6import jxl.*;
7
8public void mImportList()
9{
10this.importList = new ArrayList();
11try
12{
13
14login me = (login) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("login");
15String userId = String.valueOf(me.getID_());
16String osName = System.getProperty("os.name");
17String storedir = "";
18if(osName == null)
19osName="";
20if(osName.toLowerCase().indexOf("win") != -1)
21storedir = url + userId + "\\";
22else
23storedir = url2 + userId + "/";
24if(main.isDirExists(storedir))
25{
26storedir = storedir + "importExcel.xls";
27File file = new File(storedir);
28if(file.exists())
29{
30InputStream is = new FileInputStream(storedir);
31jxl.Workbook rwb = Workbook.getWorkbook(is);
32Sheet rs = rwb.getSheet(0);
33int rsColumns = rs.getColumns();
34int rsRows = rs.getRows();
35Cell cell;
36String code,name,brand,standard,model,material,color,unit,unit2,price,price2,note;
37boolean isImported;
38for(int i = 1; i
39{
40code=name=brand=standard=model=material=color=unit=unit2=price=price2=note="";
41isImported = false;
42
43cell = rs.getCell(0, i);
44code = cell.getContents();
45cell = rs.getCell(1, i);
46name = cell.getContents();
47cell = rs.getCell(2, i);
48brand = cell.getContents();
49cell = rs.getCell(3, i);
50standard = cell.getContents();
51cell = rs.getCell(4, i);
52model = cell.getContents();
53cell = rs.getCell(5, i);
54material = cell.getContents();
55cell = rs.getCell(6, i);
56color = cell.getContents();
57cell = rs.getCell(7, i);
58unit = cell.getContents();
59cell = rs.getCell(8, i);
60unit2 = cell.getContents();
61cell = rs.getCell(9, i);
62price = cell.getContents();
63cell = rs.getCell(10, i);
64price2 = cell.getContents();
65cell = rs.getCell(11, i);
66note = cell.getContents();
67//
68isImported = mIsRecordExistByCode(code);
69importList.add(
70new product(
71code,
72name,
73brand,
74standard,
75model,
76material,
77color,
78unit,
79unit2,
80Float.valueOf(price),
81Float.valueOf(price2),
82note,
83isImported
84));
85}
86rwb.close();
87is.close();
88}
89}
90}
91catch(Exception ex){ex.printStackTrace();}
92}
93
94
95
96public void mDownload(String path)
97{
98try
99{
100FacesContext ctx = FacesContext.getCurrentInstance();
101ctx.responseComplete();
102//String contentType = "application/octet-stream;charset=utf-8";
103String contentType = "application/x-download";
104HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
105response.setContentType(contentType);
106StringBuffer contentDisposition = new StringBuffer();
107contentDisposition.append("attachment;");
108contentDisposition.append("filename=\"");
109contentDisposition.append("exportData.xls");
110contentDisposition.append("\"");
111response.setHeader("Content-Disposition", new String(contentDisposition.toString().getBytes(System.getProperty("file.encoding")),"iso8859_1"));
112ServletOutputStream out = response.getOutputStream();
113byte[] bytes = new byte[0xffff];
114InputStream is = new FileInputStream(new File(path));
115int b = 0;
116while ((b = is.read(bytes, 0, 0xffff)) > 0)
117{
118out.write(bytes, 0, b);
119}
120is.close();
121ctx.responseComplete();
122}catch (Exception ex){ex.printStackTrace();}
123}
1import java.io.File;
2import java.io.FileInputStream;
3import java.io.FileOutputStream;
4import java.io.InputStream;
5
6import jxl.*;
7
8public void mImportList()
9{
10this.importList = new ArrayList();
11try
12{
13
14login me = (login) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("login");
15String userId = String.valueOf(me.getID_());
16String osName = System.getProperty("os.name");
17String storedir = "";
18if(osName == null)
19osName="";
20if(osName.toLowerCase().indexOf("win") != -1)
21storedir = url + userId + "\\";
22else
23storedir = url2 + userId + "/";
24if(main.isDirExists(storedir))
25{
26storedir = storedir + "importExcel.xls";
27File file = new File(storedir);
28if(file.exists())
29{
30InputStream is = new FileInputStream(storedir);
31jxl.Workbook rwb = Workbook.getWorkbook(is);
32Sheet rs = rwb.getSheet(0);
33int rsColumns = rs.getColumns();
34int rsRows = rs.getRows();
35Cell cell;
36String code,name,brand,standard,model,material,color,unit,unit2,price,price2,note;
37boolean isImported;
38for(int i = 1; i
39{
40code=name=brand=standard=model=material=color=unit=unit2=price=price2=note="";
41isImported = false;
42
43cell = rs.getCell(0, i);
44code = cell.getContents();
45cell = rs.getCell(1, i);
46name = cell.getContents();
47cell = rs.getCell(2, i);
48brand = cell.getContents();
49cell = rs.getCell(3, i);
50standard = cell.getContents();
51cell = rs.getCell(4, i);
52model = cell.getContents();
53cell = rs.getCell(5, i);
54material = cell.getContents();
55cell = rs.getCell(6, i);
56color = cell.getContents();
57cell = rs.getCell(7, i);
58unit = cell.getContents();
59cell = rs.getCell(8, i);
60unit2 = cell.getContents();
61cell = rs.getCell(9, i);
62price = cell.getContents();
63cell = rs.getCell(10, i);
64price2 = cell.getContents();
65cell = rs.getCell(11, i);
66note = cell.getContents();
67//
68isImported = mIsRecordExistByCode(code);
69importList.add(
70new product(
71code,
72name,
73brand,
74standard,
75model,
76material,
77color,
78unit,
79unit2,
80Float.valueOf(price),
81Float.valueOf(price2),
82note,
83isImported
84));
85}
86rwb.close();
87is.close();
88}
89}
90}
91catch(Exception ex){ex.printStackTrace();}
92}
93
94
95
96public void mDownload(String path)
97{
98try
99{
100FacesContext ctx = FacesContext.getCurrentInstance();
101ctx.responseComplete();
102//String contentType = "application/octet-stream;charset=utf-8";
103String contentType = "application/x-download";
104HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
105response.setContentType(contentType);
106StringBuffer contentDisposition = new StringBuffer();
107contentDisposition.append("attachment;");
108contentDisposition.append("filename=\"");
109contentDisposition.append("exportData.xls");
110contentDisposition.append("\"");
111response.setHeader("Content-Disposition", new String(contentDisposition.toString().getBytes(System.getProperty("file.encoding")),"iso8859_1"));
112ServletOutputStream out = response.getOutputStream();
113byte[] bytes = new byte[0xffff];
114InputStream is = new FileInputStream(new File(path));
115int b = 0;
116while ((b = is.read(bytes, 0, 0xffff)) > 0)
117{
118out.write(bytes, 0, b);
119}
120is.close();
121ctx.responseComplete();
122}catch (Exception ex){ex.printStackTrace();}
123}