Skip to content

Commit

Permalink
use can except some sheets
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemant committed Jan 25, 2018
1 parent b6b62e7 commit fe08bcc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
37 changes: 36 additions & 1 deletion src/main/java/com/autmatika/ReadExcel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public List<String> getListOfSheets(T service) throws IOException {
return service.getExcelWorkSheetNames();
}

public List<List<Object>> getExcelData(T service, String sheetName, String addressRangeOrUsedRange) throws IOException {
public List<List<Object>> getExcelData(T service, String sheetName, String addressRangeOrUsedRange ) throws IOException {
return service.getExcelData( sheetName, addressRangeOrUsedRange);
}

Expand All @@ -35,11 +35,46 @@ public String[][] getExcelDataInStringArray(T service, String sheetName, String
}


public String[][] getExcelDataInStringArray(T service, String addressRangeOrUsedRange, List<String> exceptedSheetsList) throws IOException {

List<String[][]> listOfTables = new ArrayList<>();

List<String> sheets = getListOfSheets(service);
sheets.removeAll(exceptedSheetsList);

boolean firstRow = true;
for (String sheet : sheets) {

//Removing the first row from the subsequent tables/ sheets to keep header row only once
if (firstRow == true) {
firstRow = false;
listOfTables.add(getStrings(getExcelDataInStringFormat(service, sheet, addressRangeOrUsedRange)));
} else {
String[][] src = getStrings(getExcelDataInStringFormat(service, sheet, addressRangeOrUsedRange));
String[][] dest = new String[src.length - 1][src[0].length];

for (int i = 1; i < src.length; i++) {
System.arraycopy(src[i], 0, dest[i - 1], 0, src[0].length - 1);
}
listOfTables.add(dest);
}


}

String[][] temp = null;
for (String[][] table : listOfTables) {
temp = (String[][]) ArrayUtils.addAll(temp, table);
}
return temp;
}

public String[][] getExcelDataInStringArray(T service, String addressRangeOrUsedRange) throws IOException {

List<String[][]> listOfTables = new ArrayList<>();

List<String> sheets = getListOfSheets(service);

boolean firstRow = true;
for (String sheet : sheets) {

Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/autmatika/ReadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.testng.annotations.Test;

import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

Expand Down Expand Up @@ -120,8 +121,11 @@ public void testLocalExcelIfItBringCellsOnRange() throws Exception {
List<List<Object>> list = readExcel.getExcelData(office, "SmokeTest", "UsedRange");
System.out.println(list);

readExcel.getExcelDataInStringArray(office,"UsedRange");
// readExcel.getExcelDataInStringArray(office,"UsedRange");

readExcel.getExcelDataInStringArray(office,"UsedRange", Arrays.asList("DoNotConsider"));
}



}
Binary file modified src/test/resources/SmokeTests.xlsx
Binary file not shown.

0 comments on commit fe08bcc

Please sign in to comment.