-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSiteData.java
64 lines (56 loc) · 2.06 KB
/
SiteData.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
package project_A;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class SiteData {
String Data[];
String Header[];
@SuppressWarnings({ "deprecation", "resource" })
public String[] getData(String code) throws IOException, URISyntaxException{
InputStream file = new Source().getFile();
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet spreadsheet = workbook.getSheetAt(1);
String value;
XSSFRow row;
for (int rowIndex = 0; rowIndex <= spreadsheet.getLastRowNum(); rowIndex++) {
row = spreadsheet.getRow(rowIndex);
Cell cell = row.getCell(0, Row.CREATE_NULL_AS_BLANK);
cell.setCellType(Cell.CELL_TYPE_STRING);
value = cell.getStringCellValue();
if(value.contentEquals(code)){
int y =0; Data=new String[row.getLastCellNum()];
while (y <=row.getLastCellNum()-1){
Cell cell2 = row.getCell(y, Row.CREATE_NULL_AS_BLANK);
cell2.setCellType(Cell.CELL_TYPE_STRING);
Data[y]=cell2.getStringCellValue();
y++;
}
}
file.close();
}
return Data;
}
@SuppressWarnings({ "unused", "deprecation", "resource" })
public String[] getHeader () throws IOException, URISyntaxException{
InputStream file = new Source().getFile();
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet spreadsheet = workbook.getSheetAt(2);
String value;
XSSFRow row;
row = spreadsheet.getRow(0);
int z =0; Header=new String[row.getLastCellNum()];
while (z <=row.getLastCellNum()-1){
Cell cell = row.getCell(z, Row.CREATE_NULL_AS_BLANK);
cell.setCellType(Cell.CELL_TYPE_STRING);
Header[z]=cell.getStringCellValue();
z++;
}
file.close();
return Header;
}
}