import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import jxl.read.biff.BiffException;
import jxl.read.*;
public class Prac5_TestNG {
@BeforeClass
public void f1(){}
@Test
public static void testImportExport() throws Exception{
//taking the data from our excel sheet and creating a workbook for it
FileInputStream fi = new FileInputStream("C:\\Users\\****\\*****rojects\\Students-Record.xlsx");
Workbook wb = Workbook.getWorkbook(fi);
//Creating an excel sheet
Sheet s = wb.getSheet(0); // to get the first sheet we use indexing.
String[][] a = new String[s.getRows()][s.getColumns()];
FileOutputStream fo = new FileOutputStream("C:\\Users\\****\\****Projects\\Students-Record.xlsx");
WritableWorkbook wwb = Workbook.createWorkbook(fo);
WritableSheet ws = wwb.createSheet("Result1", 0); //creating a new workbook and using it's first sheet
for (int i = 0; i < s.getRows(); i++)
for (int j = 0; j < s.getColumns(); j++) {
a[i][j] = s.getCell(j, i).getContents();
//to add the contents from original excel sheet to the new one.
Label l2 = new Label(j, i, a[i][j]);
ws.addCell(l2);
//To create a new heading by the name Result at in the new excel sheet
Label l1 = new Label(6, 0, "Result");
ws.addCell(l1);
}
for (int i = 0; i < s.getRows(); i++)
for (int j = 0; j < s.getColumns(); j++) {
a[i][j] = s.getCell(j, i).getContents();
int x = Integer.parseInt(a[i][j]);
if (x > 35) {
Label l = new Label(6, i, "pass");
ws.addCell(l);
} else {
Label l = new Label(6, i, "fail");
ws.addCell(l);
break;
}
wwb.write();
}
wwb.close();
}
}
This a program to access and modify a local excel sheet using java. It should be able to create a new cell "Result" with a value pass or fail depending upon if the student scores more than 35 or not in all subjects. The error it gives is that it first says that jxl.read doesn't exist. When I remove that import statement it gives a whole lot of another errors.
This is the error below(I don't understand what's going on though)
:
"C:\Program Files\Java\jdk-17.0.1\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.3\lib\idea_rt.jar=61715:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.3\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2.3\plugins\testng\lib\testng-rt.jar;C:\Users\User\IdeaProjects\SQA_Prac5\out\production\SQA_Prac5;D:\Live Desktop & Documents\Downloads\testng-7.6.1.jar;D:\Live Desktop & Documents\Downloads\jxl-2.6.12.jar" com.intellij.rt.testng.RemoteTestNGStarter -usedefaultlisteners false -socket61714 @w@C:\Users\User\AppData\Local\Temp\idea_working_dirs_testng.tmp -temp C:\Users\User\AppData\Local\Temp\idea_testng.tmp
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:105)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 1 more
NOTE: This is a practical from my college that I might be asked to do during the practical exam. The teacher insists that as we know the java syntax we should be able to do it on our own. Please Help!