-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGMap_data.java
77 lines (70 loc) · 3.03 KB
/
GMap_data.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
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 GMap_data {
static double Lat[];
static double Long[];
static String Name[];
//opens an excel sheet and reads the value from the 2nd col
//stores them in an array and returns the array
@SuppressWarnings({ "resource", "deprecation" })
public double[] getLat() throws IOException, URISyntaxException{
InputStream file = new Source().getFile();//gets the source i.e. file path
XSSFWorkbook workbook = new XSSFWorkbook(file);//opens the excel file
XSSFSheet spreadsheet = workbook.getSheetAt(3);//opens the relevant sheet
XSSFRow row; //used to store the row
Lat=new double[spreadsheet.getLastRowNum()+1];//used to store the excel data
for (int rowIndex = 0; rowIndex <= spreadsheet.getLastRowNum(); rowIndex++) {
row = spreadsheet.getRow(rowIndex);//stored row
Cell cell = row.getCell(1, Row.CREATE_NULL_AS_BLANK);//stores cell data from a specified col
cell.setCellType(Cell.CELL_TYPE_NUMERIC);//change data to numeric value
Lat[rowIndex] = cell.getNumericCellValue();//store value in array
}
file.close();//close file
return Lat;//return array
}
//similar to the above method
//opens an excel sheet and reads the value from the 3rd col
//stores them in an array and returns the array
@SuppressWarnings({ "resource", "deprecation" })
public double[] getLong() throws IOException, URISyntaxException{
InputStream file = new Source().getFile();
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet spreadsheet = workbook.getSheetAt(3);
XSSFRow row;
Long=new double[spreadsheet.getLastRowNum()+1];
for (int rowIndex = 0; rowIndex <= spreadsheet.getLastRowNum(); rowIndex++) {
row = spreadsheet.getRow(rowIndex);
Cell cell = row.getCell(2, Row.CREATE_NULL_AS_BLANK);
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
Long[rowIndex] = cell.getNumericCellValue();
}
file.close();
return Long;
}
//similar to above method
//opens a excel sheet and reads the value from the 1st col
//stores them in an array and returns the array
@SuppressWarnings({ "resource", "deprecation" })
public String[] getTitle() throws IOException, URISyntaxException{
InputStream file = new Source().getFile();
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet spreadsheet = workbook.getSheetAt(3);
XSSFRow row;
Name=new String[spreadsheet.getLastRowNum()+1];
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);
Name[rowIndex]=cell.getStringCellValue();
}
file.close();
return Name;
}
}