Load Excel cell values using apache poi

Asked 1 years ago, Updated 1 years ago, 138 views

I wanted to use Excel's function _xlfn.T.INV.2T(B2,C2) while I was programming in Java, so I made a function with Apache Poi and got to the point where I could display it on Excel.

Therefore, I would like to double the value of D2 in the java variable, but I don't know how to do it.It may just be a bad way to look it up, but it doesn't work no matter what website you go to.
(If you have any recommendations, please let me know.)

Below is the code for creating the Excel file.

Also, Excel was only used by a function, so if you have time, please let me know if there is a program that automatically deletes Excel files every time.
Please.

I want the D2 part of this picture

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
import java.util.Scanner;

public class Main
{
    public static void Welch_test()
    {
        System.out.println("Test population mean two different populations are same or not");
        System.out.println("This program works only for two-tailed";

        Scanner in = new Scanner (System.in);
        System.out.println("Do you want population with same variation(Type1) or different variation(Type2):");
        int type = in.nextInt();

        System.out.println("How many samples did you take from first population:");
        double na = in.nextDouble();

        System.out.println("How many samples did you take from second population:");
        double nb = in.nextDouble();

        System.out.println("What is your Sample mean for first population:");
        double Xa = in.nextDouble();

        System.out.println("What is your Sample mean for second population:");
        double Xb = in.nextDouble();

        System.out.println("What is unbias variance for first population:");
        doubleUa=in.nextDouble();

        System.out.println("What is unbied variance for second population:");
        double Ub = in.nextDouble();

        System.out.println("What is Level of Signature (Type with %-value)");
        double L = in.nextDouble();
        double = L/100;
        System.out.println("App value" + l + "was considered statistically signatory.");

        if(type==1)
        {
            doublek = na+nb-2;
            doublep = Math.abs (Xa-Xb);
            double one=(1/na)+(1/nb));
            double two=(((Ua)*(na-1)))+((Ub)*(nb-1)))/(na+nb-2);
            double three=one*two;
            double q = Math.sqrt(three);
            double T = p/q;
            System.out.println("Degre of freedom"+k);
            System.out.println("Test statistics" + T);

            Workbook wb = new XSSFWorkbook();
            Sheet sheet = wb.createSheet();
            Row1 = sheet.createRow(1);

            Cellcell1_1=row1.createCell(1);
            Cell cell1_2=row1.createCell(2);
            Cell cell1_3 = row1.createCell(3);

            cell1_1.setCellValue(l);
            cell1_2.setCellValue(k);
            cell1_3.setCellFormula("_xlfn.T.INV.2T(B2,C2)";

            FileOutputStream out=null;
            try{
                out = new FileOutputStream("T-inverse.xlsx");
                wb.write(out);
            } catch(IOExceptione){
                System.out.println(e.toString());
            } US>finally
                try{
                    out.close();
                } catch(IOExceptione){
                    System.out.println(e.toString());
                }
            }
        }
        else
        {
            doublex = Math.abs (Xa-Xb);
            doubley = Math.sqrt(Ua/na)+(Ub/nb));
            double z = x/y;
            double parta = Math.power((Ua/na)+(Ub/nb))), 2);
            double part=Math.power(Ua/na), 2);
            double partn = Math.power(Ub/nb), 2);
            double partb=(partm/(na-1));
            double partc=(partn/(nb-1));
            double partd = partb+partc;
            double j=parta/partd;
            j = Math.round(j);
            System.out.println("Degre of Freedom" + j);
            System.out.println("Test statistic is"+z);

            Workbook wb = new XSSFWorkbook();
            Sheet sheet = wb.createSheet();
            Row1 = sheet.createRow(1);

            Cellcell1_1=row1.createCell(1);
            Cell cell1_2=row1.createCell(2);
            Cell cell1_3 = row1.createCell(3);

            cell1_1.setCellValue(l);
            cell1_2.setCellValue(j);
            cell1_3.setCellFormula("_xlfn.T.INV.2T(B2,C2)";

            FileOutputStream out=null;
            try{
                out = new FileOutputStream("T-inverse.xlsx");
                wb.write(out);
            } catch(IOExceptione){
                System.out.println(e.toString());
            } US>finally
                try{
                    out.close();
                } catch(IOExceptione){
                    System.out.println(e.toString());
                }
            }
        }
    }
    public static void main (String[]args)
    {
        Welch_test();
    }
}

java excel apache-poi

2022-09-30 21:45

1 Answers

If you just want to get the cell calculation results, you should be able to get them with getNumericCellValue

double result=cell1_3.getNumericCellValue();

However, if you look at the T.INV.2T function reference, you may also get the error values #VALUE! and #NUM!, so you may need to code them with that in mind.

Strictly speaking, you need to use an interface called FormulaEvaluator to get CellValues from Cell objects and branch processing by cell type (I've never really done that before, so I can't say for sure, so I'll leave it up to the questioner to decide).


2022-09-30 21:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.