-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSignUpToExcel.java
137 lines (113 loc) · 4.31 KB
/
SignUpToExcel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package invertorymanagement;
import java.io.*;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* @author partha
*/
public class SignUpToExcel {
////////////////////////////////////// variables /////////////////////////
static String [] Column = {"Name","Phone Number","ID","Password","Gender"};
// static ArrayList<SignUp> Signup =new ArrayList<>();
static List<SignUp> signup = new ArrayList<SignUp>();
/////////////////////////// io //////////////////////////////
static File file=new File("Login.xlsx");
static FileWriter fileWriter;
static FileReader fileReader;
// static WritableWorkbook myWorkbook ;
static HSSFWorkbook workbook;
static Row hearderRow;
static CellStyle headCellStyle;
//////////////////////////////////////////
static String Name;
static String PhoneNum;
static String ID;
static String Password;
static String Gender;
static HSSFSheet mysFSheet;
static org.apache.poi.ss.usermodel.Font font;
static File f= new File("Rowdata.txt");
static FileWriter fw;
static FileReader fr;
static int rownum=1;
static String rowread;
static int r;
static BufferedReader bf;
public SignUpToExcel(String Name,String PhoneNum,String ID,String Password,String Gender) throws NullPointerException, FileNotFoundException, IOException{
this.Name =Name;
this.PhoneNum=PhoneNum;
this.ID = ID;
this.Password =Password;
this.Gender=Gender;
signup.add(new SignUp(Name,PhoneNum, ID, Password,Gender));
if(!file.exists()){
workbook = new HSSFWorkbook();
mysFSheet = workbook.createSheet("Contacts");
}
else{
workbook =new HSSFWorkbook(new FileInputStream(file));
mysFSheet=workbook.getSheet("Contacts");
}
font = workbook.createFont();
font.setBold(true);
font.setFontHeightInPoints((short)14);
font.setColor(IndexedColors.BLUE.getIndex());
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setFont(font);
Row headerRow = mysFSheet.createRow(0);
for(int i=0;i<Column.length;i++){
Cell cell = headerRow.createCell(i);
cell.setCellValue(Column[i]);
}
for (SignUp signUp :signup ) {
if(f.exists()){
bf=new BufferedReader( new FileReader(f));
rowread=bf.readLine();
rownum=Integer.parseInt(rowread);
rownum++;
fw=new FileWriter(f);
fw.write(""+rownum);
fw.close();
System.out.println(rowread);
}
else{
fw=new FileWriter(f);
fw.write(""+rownum);
fw.close();
bf=new BufferedReader( new FileReader(f));
rowread=bf.readLine();
rownum=Integer.parseInt(rowread);
System.out.println(rowread);
}
Row row = mysFSheet.createRow(rownum);
row.createCell(0).setCellValue(SignUp.Name);
row.createCell(1).setCellValue(SignUp.PhoneNum);
row.createCell(2).setCellValue(SignUp.ID);
row.createCell(3).setCellValue(SignUp.Password);
row.createCell(4).setCellValue(signUp.Gender);
}
signup.clear();
for(int i=0;i<Column.length;i++){
mysFSheet.autoSizeColumn(i);
}
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
workbook.close();
fos.close();
}
}