Example usage for org.apache.poi.ss.usermodel Workbook getSheetAt

List of usage examples for org.apache.poi.ss.usermodel Workbook getSheetAt

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook getSheetAt.

Prototype

Sheet getSheetAt(int index);

Source Link

Document

Get the Sheet object at the given index.

Usage

From source file:net.cpollet.jixture.fixtures.transformers.ExcelFileFixtureTransformer.java

License:Apache License

@Override
protected List<Object> parse(From fixture) {
    InputStream inputStream = fixture.getInputStream();
    Workbook workbook = createWorkbook(inputStream);

    DataFormatter dataFormatter = new DataFormatter();
    FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();

    List<Object> mappings = new LinkedList<Object>();
    Helpers helpers = new Helpers();
    helpers.dataFormatter = dataFormatter;
    helpers.evaluator = evaluator;//  w  w w.j  ava 2 s . c o m

    Parameters parameters = new Parameters();
    parameters.mode = fixture.getMode();

    for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
        Sheet sheet = workbook.getSheetAt(sheetIndex);

        mappings.addAll(parseSheet(sheet, helpers, parameters));
    }

    return mappings;
}

From source file:net.lizhaoweb.maker.code.java.model.excel.read.ExcelFileReader.java

License:Open Source License

private Set<ClassInformation> analysisBySheetIndex(Configuration configuration, List<Integer> sheetIndexes,
        Workbook workbook) {
    if (sheetIndexes == null) {
        throw new IllegalArgumentException("The sheet index list is null");
    }//  w  w  w  . j a v a  2 s  .com
    if (workbook == null) {
        throw new IllegalArgumentException("The excel workbook is null");
    }
    Map<Integer, ClassInformation> classDataMap = new HashMap<Integer, ClassInformation>();

    // ??
    ExecutorService classNameExecutorService = Executors.newCachedThreadPool();
    List<Future<Map<Integer, String>>> classNameFutureList = new ArrayList<Future<Map<Integer, String>>>();

    // Sheet Map
    Map<Integer, Sheet> sheetMap = new HashMap<Integer, Sheet>();

    for (Integer sheetIndex : sheetIndexes) {
        Sheet sheet = workbook.getSheetAt(sheetIndex);
        sheetMap.put(sheetIndex, sheet);
        this.traversingSheet(configuration, classDataMap, classNameExecutorService, classNameFutureList,
                sheetIndex, sheet);
    }
    return this.getClassDatasFromFuture(configuration, classDataMap, classNameExecutorService,
            classNameFutureList, sheetMap);
}

From source file:net.morphbank.loadexcel.ReadExternalLinks.java

License:Open Source License

public ReadExternalLinks(String filename, GetConnection conn) {
    connect = conn;/* www  .ja v a2  s  . co m*/
    String fname = filename;

    result = null;
    statement = null;
    metadata = null;

    try {
        InputStream inp = new FileInputStream(fname);
        Workbook workbook = WorkbookFactory.create(inp);

        // extract the sheets from a formed workbook
        Links = workbook.getSheetAt(0);

    } catch (Exception ioexception) {
        ioexception.printStackTrace();
    }
}

From source file:net.morphbank.loadexcel.SheetReader.java

License:Open Source License

public SheetReader(String filename, GetConnection conn) {
    connect = conn;//  ww  w  .ja v  a2  s  .c  o  m
    fname = filename;

    result = null;
    statement = null;
    metadata = null;

    try {

        InputStream inp = new FileInputStream(fname);
        Workbook workbook = WorkbookFactory.create(inp);

        // extract the sheets from a formed workbook
        imageCollectionSheet = workbook.getSheetAt(0);
        imageSheet = workbook.getSheetAt(1);
        viewSheet = workbook.getSheetAt(2);
        taxonSheet = workbook.getSheetAt(4);
        specimenSheet = workbook.getSheetAt(3);
        localitySheet = workbook.getSheetAt(5);
        extLinkSheet = workbook.getSheetAt(6);
        supportDataSheet = workbook.getSheetAt(7);
        protectedDataSheet = workbook.getSheetAt(9);
        readHeaders();
        setReleaseDate();

    } catch (Exception ioexception) {
        ioexception.printStackTrace();
    }
}

From source file:net.morphbank.mbsvc3.fsuherb.XlsFieldMapper.java

License:Open Source License

public XlsFieldMapper(String fileName) {
    try {//w  ww .j ava  2  s . com
        this.fileName = fileName;
        InputStream inp = new FileInputStream(fileName);
        Workbook workbook = WorkbookFactory.create(inp);
        views = workbook.getSheetAt(0);
        readHeaders();
        lastLine = views.getLastRowNum() - 1;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.morphbank.mbsvc3.mapsheet.XlsFieldMapper.java

License:Open Source License

public XlsFieldMapper(String fileName) {
    try {//w  w  w. j av  a 2 s.  com

        this.fileName = fileName;
        InputStream inp = new FileInputStream(fileName);
        Workbook workbook = WorkbookFactory.create(inp);
        views = workbook.getSheetAt(0);
        credentialSheet = workbook.getSheetAt(2);
        links = workbook.getSheetAt(1);
        readHeaders();
        lastLine = views.getLastRowNum() - 1;

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.pcal.sqlsheet.XlsStatement.java

License:Apache License

private static Sheet getSheetNamed(Workbook wb, String name) throws SQLException {
    if (name == null)
        throw new IllegalArgumentException();
    name = name.trim();/*from  w  ww . j  a v  a2s.c om*/
    String allSheetNames = "";
    int count = wb.getNumberOfSheets();
    for (int i = 0; i < count; i++) {
        String sheetName = wb.getSheetName(i);
        allSheetNames += sheetName + ",";
        if (sheetName == null)
            continue;
        if (sheetName.equalsIgnoreCase(name) || ("\"" + sheetName + "\"").equalsIgnoreCase(name)) {
            return wb.getSheetAt(i);
        }
    }

    String message = "No sheet named '" + name;
    if (count == 0) {
        message += " can be found. Are you sure of the Excel file path ?";
    } else {
        if (allSheetNames.length() > 2) {
            allSheetNames = allSheetNames.substring(0, allSheetNames.length() - 1);
        }
        message += ". Only the following " + count + " sheets can be found (" + allSheetNames + ")";
    }
    throw new SQLException(message);
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse workbook/*  ww w  .  jav  a  2s  .  c om*/
 * 
 * @param context
 * @param wb
 * @throws ExcelException
 */
public static void parseWorkbook(Object context, Workbook wb) throws ExcelException {
    try {
        int sheetCount = wb.getNumberOfSheets();
        for (int sheetIndex = 0; sheetIndex < sheetCount; sheetIndex++) {
            Sheet sheet = wb.getSheetAt(sheetIndex);
            parseSheet(context, wb, sheet);
            // set print area
            WorkbookUtils.setPrintArea(wb, sheetIndex);
        }
    } catch (Exception e) {
        throw new ExcelException("parseWorkbook error: ", e);
    }
}

From source file:net.sf.excelutils.ExcelUtils.java

License:Apache License

/**
 * parse Workbook//from  w w w . j a v a  2s.  c o m
 * 
 * @param context
 * @param wb
 * @param sheetIndex
 * @throws ExcelException
 */
public static void parseWorkbook(Object context, Workbook wb, int sheetIndex) throws ExcelException {
    try {
        Sheet sheet = wb.getSheetAt(sheetIndex);
        if (null != sheet) {
            parseSheet(context, wb, sheet);
            // set print area
            WorkbookUtils.setPrintArea(wb, sheetIndex);
        }

        int i = 0;
        while (i++ < sheetIndex) {
            wb.removeSheetAt(0);
        }

        i = 1;
        while (i < wb.getNumberOfSheets()) {
            wb.removeSheetAt(i);
        }
    } catch (Exception e) {
        throw new ExcelException("parseWorkbook error: ", e);
    }
}