Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import jxl.*;
  2. import jxl.write.*;
  3.  
  4. import java.io.*;
  5.  
  6. import org.testng.annotations.Test;
  7.  
  8. public class Practical_6 {
  9.  
  10. @Test
  11. public void testImportExport1() throws Exception {
  12. File xlsInputFile = new File("E:\\Ty\\ST\\input.xls"); // Get Inputs from this xls
  13. File xlsOutputFile = new File("E:\\Ty\\ST\\output.xls"); // Stream Output to this xls
  14.  
  15. FileInputStream fi = new FileInputStream(xlsInputFile);
  16. FileOutputStream fo = new FileOutputStream(xlsOutputFile);
  17.  
  18.  
  19. Workbook inputWorkbook = Workbook.getWorkbook(fi);
  20. Sheet inputWorkbookSheet = inputWorkbook.getSheet(0);
  21.  
  22. WritableWorkbook outputWorkbook = Workbook.createWorkbook(fo);
  23. WritableSheet outputWorkbookSheet = outputWorkbook.createSheet("result", 0);
  24.  
  25. int tempRow = 0; // Maintains row in result xls file
  26. for (int i = 1; i < inputWorkbookSheet.getRows(); i++) {
  27. // Iterate each row, starting from 2nd row (since 1st is just labels)
  28.  
  29. for (int k = 2; k <= 4; k++) {
  30. // Iterate through subjects (X,Y,Z), if any subject
  31. // has marks greater then 60 then output that in xls
  32. String b = inputWorkbookSheet.getCell(k, i).getContents();
  33. int x = Integer.parseInt(b);
  34.  
  35. if (x > 60) {
  36. for (int j = 0; j < inputWorkbookSheet.getColumns(); j++) {
  37. String colLabel = inputWorkbookSheet.getCell(j, i).getContents() ;
  38. Label l2 = new Label(j, tempRow, colLabel);
  39. outputWorkbookSheet.addCell(l2);
  40. }
  41.  
  42. tempRow++;
  43. break; // Skip further iterations
  44. }
  45. }
  46.  
  47. }
  48. outputWorkbook.write();
  49. outputWorkbook.close();
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement