Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>if you want to use java to manipulate excel data the best choise for me was apache POI There're a lot's of tutorials on official site, if you ned some help in code you can ask and we try to help you.</p> <p>Add this two methods to your code</p> <pre><code>private static double getSubstraction(double summ, String your) { if (your.contains("-")) { return summ + Double.parseDouble(your.replace("-", "")); } else if (your.contains("+")) { return summ - Double.parseDouble(your.replace("+", "")); } else { return summ - Double.parseDouble(your); } } private static double getSumm(double sub, String your) { if (your.contains("-")) { return sub - Double.parseDouble(your.replace("-", "")); } else if (your.contains("+")) { return sub + Double.parseDouble(your.replace("+", "")); } else { return sub + Double.parseDouble(your); } } </code></pre> <p>define two global variables <code>double summ</code> and <code>double sub</code> for example</p> <pre><code>public class MainCreator { public static void main(String[] args) throws IOException { FileInputStream file = new FileInputStream(new File("workbook.xls")); Workbook wb = new HSSFWorkbook(file); Sheet sh = wb.getSheetAt(0); int lastRownum = sh.getLastRowNum(); double summ = 0; double sub = 0; for (int i = 0; i &lt; lastRownum + 1; i++) { Row row = sh.getRow(i); Cell cell1 = row.getCell(1); Cell cell2 = row.getCell(2); if (cell1 != null &amp;&amp; cell2 != null) { String cellValue1 = cell1.getStringCellValue(); String cellValue2 = cell2.getStringCellValue(); String stringNumber = cellValue2.split("=")[1].trim(); if (cellValue1.contains("ADD")) { if (cellValue2.split("=")[1].trim().contains("PATH DOES NOT EXIST")) { System.out.println("Path Does Not Exist"); } else { System.out.println(cellValue1 + "/" + stringNumber); summ = getSumm(summ, stringNumber); } } else if (cellValue1.contains("SUB")) { if (cellValue2.split("=")[1].trim().contains("PATH DOES NOT EXIST")) { System.out.println("Path Does Not Exist"); } else { System.out.println(cellValue1 + "/" + stringNumber); sub = getSubstraction(sub, stringNumber); } } else { System.out.println("Smt wrong"); } } } System.out.println("Summ = " + summ); System.out.println("Sub = " + sub); } private static double getSubstraction(double main, String your) { if (your.contains("-")) { return main + Double.parseDouble(your.replace("-", "")); } else if (your.contains("+")) { return main - Double.parseDouble(your.replace("+", "")); } else { return main - Double.parseDouble(your); } } private static double getSumm(double main, String your) { if (your.contains("-")) { return main - Double.parseDouble(your.replace("-", "")); } else if (your.contains("+")) { return main + Double.parseDouble(your.replace("+", "")); } else { return main + Double.parseDouble(your); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload