Actually i have many column and rows rumber in excel which are hard to count.But in my program i have tried to print for column 0,1,2,3.I am able to print upto the column i can count.But when i move further i cannot get the required information about that column to print the data. Suppose the datas are located in GQ column then how can i only print the datas of GQ column??The code i have posted here prints all the columns and rows.But i need only specific of GQ column.
public class Program {
public static final String SAMPLE_XLSX_FILE_PATH = "D:\\Book1.xlsx";
public static void main(String[] args) throws IOException, InvalidFormatException {
// Creating a Workbook from an Excel file (.xls or .xlsx)
Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));
// Retrieving the number of sheets in the Workbook
System.out.println("Workbook has " + workbook.getNumberOfSheets() + " Sheets : ");
// 2. Or you can use a for-each loop
System.out.println("Retrieving Sheets using for-each loop");
for(Sheet sheet: workbook) {
System.out.println("=> " + sheet.getSheetName());
}
// Getting the Sheet at index zero
Sheet sheet = workbook.getSheetAt(0);
// Create a DataFormatter to format and get each cell's value as String
DataFormatter dataFormatter = new DataFormatter();
// using for each loop to iterate over rows and colums
System.out.println("\n\nIterating over Rows and Columns using for-each loop\n");
for (Row row: sheet) {
//System.out.println(row.getCell(0));
for(Cell cell: row) {
String cellValue = dataFormatter.formatCellValue(cell);
System.out.print(cellValue + "\t");
}
System.out.println();
}
// Closing the workbook
workbook.close();
}
}