Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.Map.Entry;
- import java.util.TreeMap;
- import org.apache.poi.xssf.usermodel.XSSFCell;
- import org.apache.poi.xssf.usermodel.XSSFRow;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- public class Excel {
- public static void main(String[] args) throws IOException {
- ArrayList<String> offices = new ArrayList<String>();
- ArrayList<Double> incomes = new ArrayList<Double>();
- InputStream myxls = new FileInputStream("Incomes-Report.xlsx");
- XSSFWorkbook wb = new XSSFWorkbook(myxls);
- XSSFSheet sheet = wb.getSheetAt(0);
- for (int i = 1; i <= 11; i++) {
- XSSFRow rowOffice = sheet.getRow(i);
- XSSFCell cellOffice = rowOffice.getCell(0);
- XSSFRow rowIncomes = sheet.getRow(i);
- XSSFCell cellIncomes = rowIncomes.getCell(3);
- XSSFRow rowVat = sheet.getRow(i);
- XSSFCell cellVat = rowVat.getCell(4);
- offices.add(cellOffice.getStringCellValue().trim());
- incomes.add(cellIncomes.getNumericCellValue()
- + cellVat.getNumericCellValue());
- }
- TreeMap<String, Double> total = new TreeMap<String, Double>();
- double grandTotal = 0.0d;
- for (int i = 0; i < offices.size(); i++) {
- Double temp = total.get(offices.get(i));
- if (temp == null) {
- temp = 0.0d;
- }
- total.put(offices.get(i), temp + incomes.get(i));
- grandTotal += incomes.get(i);
- }
- for (Entry<String, Double> wordEntry : total.entrySet()) {
- System.out.printf("%s Total -> %.2f%n", wordEntry.getKey(), wordEntry.getValue());
- }
- System.out.printf("Grand Total -> %.2f", grandTotal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement