
// GetThaiData.java
// Andrew Davison, ad@coe.psu.ac.th, Nov. 2022

/*  Print out all the Thai province names and their 3-letter codes
    obtained from "Thailand.xlsx"

    Compare this to Extractor.java

  Usage:
    > compile GetThaiData.java
    > run GetThaiData
*/


import java.io.*;

import org.apache.poi.ss.usermodel.*;


public class GetThaiData
{
  private static final String SS_FNM = "Thailand.xlsx";


  public static void main(String[] args)
  {
    try (FileInputStream fis = new FileInputStream(SS_FNM)) {
      System.out.println("Reading from " + SS_FNM);

      // Handles both XSSF and HSSF automatically
      Workbook workbook = WorkbookFactory.create(fis);
      Sheet sheet = workbook.getSheetAt(0);  // Get first sheet

      for (Row row : sheet) {
        if (row.getRowNum() == 0)  // skip header
          continue;
        String provName = row.getCell(0).getStringCellValue().trim();
        String codeName = row.getCell(6).getStringCellValue().trim();
        System.out.println(provName + ":\t" + codeName);
      }
    }
    catch (Exception e) 
    {  System.out.println(e);  }

  } // end of main()


}  // end of GetThaiData class
