Java Code Examples for org.apache.poi.xssf.usermodel.XSSFWorkbook#getSheet()

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFWorkbook#getSheet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XSSFExcelWriterReader.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an existing sheet. If there is no sheet with this name a new will be created
 *
 * @param name name of sheet
 * @return an existing or new sheet
 * @see
 */
public XSSFSheet getSheet(XSSFWorkbook wb, String name) {
  // try to get row
  XSSFSheet sheet = wb.getSheet(name);
  // if not exist: create row
  if (sheet == null)
    sheet = wb.createSheet(name);
  // get cell
  return sheet;
}
 
Example 2
Source File: PoiXSSFExcelUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static List<List<String>> readSingleExcelSheet(InputStream inputStream,String sheetName) throws IOException {
	XSSFWorkbook xssfWorkbook = new XSSFWorkbook(inputStream);
	XSSFSheet xssfSheet = xssfWorkbook.getSheet(sheetName);
	List<List<String>> list = readSheet(xssfSheet);
	xssfWorkbook.close();
	return list;
}
 
Example 3
Source File: PoiXSSFExcelUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static List<?> readSingleExcelSheet(InputStream inputStream,String sheetName,Map<Integer,String> map,Class<?> objectClass) throws Exception {
	XSSFWorkbook xssfWorkbook = new XSSFWorkbook(inputStream);
	XSSFSheet xssfSheet = xssfWorkbook.getSheet(sheetName);
	List<?> list = readSheet(xssfSheet,map,objectClass);
	xssfWorkbook.close();
	return list;
}
 
Example 4
Source File: XSSFExcelWriterReader.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an existing sheet. If there is no sheet with this name a new will be created
 * 
 * @param name name of sheet
 * @return an existing or new sheet
 * @see
 */
public XSSFSheet getSheet(XSSFWorkbook wb, String name) {
  // try to get row
  XSSFSheet sheet = wb.getSheet(name);
  // if not exist: create row
  if (sheet == null)
    sheet = wb.createSheet(name);
  // get cell
  return sheet;
}
 
Example 5
Source File: AccessTemplateServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public void writeObjectSheet(XSSFWorkbook workBook, String obj, String menu, String app) {

    XSSFSheet sheet = workBook.getSheet(app);
    if (sheet == null) {
      sheet = workBook.createSheet(app);
      writeRow(sheet, objectHeaders);
    }
    String usersRights = appMenus.contains(menu) ? "rwcde" : "r";
    writeRow(sheet, new String[] {obj, usersRights, "rwcde"});
  }
 
Example 6
Source File: AccessTemplateServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeMenuSheet(XSSFWorkbook workBook, String menu, String app) {
  XSSFSheet sheet = workBook.getSheet(app + "-menu");
  if (sheet == null) {
    sheet = workBook.createSheet(app + "-menu");
    writeRow(sheet, menuHeaders);
  }
  String usersRights = configMenus.contains(menu) ? "" : "x";
  writeRow(sheet, new String[] {menu, usersRights, "x"});
  appMenus.remove(menu);
}
 
Example 7
Source File: ExcelFileParser.java    From JTAF-XCore with Apache License 2.0 5 votes vote down vote up
public ExcelFileParser(String fileName, String sheetName, boolean isXlsx) throws Exception {
	if (isXlsx) {
		workBookXlsx = new XSSFWorkbook(new FileInputStream(fileName));
		workBookSheetXlsx = workBookXlsx.getSheet(sheetName);
	} else {
		workBookXls = new HSSFWorkbook(new FileInputStream(fileName));
		workBookSheetXls = workBookXls.getSheet(sheetName);
	}
}
 
Example 8
Source File: readExcelXLSX.java    From Selenium with The Unlicense 4 votes vote down vote up
public static String[][] readExcel(String absolutePathToFile) {

		// A Two dimensional array of Strings which represents the data in the
		// sheet
		String[][] data = null;
		try {
			// A Buffered File Input Stream to read the data
			InputStream is = new BufferedInputStream(new FileInputStream(
					absolutePathToFile));
			// Workbook representing the excel file
			XSSFWorkbook wb = new XSSFWorkbook(is);
			// Next a sheet which represents the sheet within that excel file
			XSSFSheet sheet = wb.getSheet("Details");
			// No of rows in the sheet
			int rowNum = sheet.getLastRowNum() + 1;
			// No of columns in the sheet
			int colNum = sheet.getRow(0).getLastCellNum();
			data = new String[rowNum][colNum];
			for (int i = 0; i < rowNum; i++) {
				// Get the row
				XSSFRow row = sheet.getRow(i);
				for (int j = 0; j < colNum; j++) {
					// Get the columns or cells for the first row and keep
					// looping
					// for the other rows
					XSSFCell cell = row.getCell(j);
					// Make a call to the method cellToString which actually
					// converts the cell contents to String
					String value = cellToString(cell);
					data[i][j] = value;
					// Logic for handling the data
					// You can write the logic here, or leave the method as it
					// is to return a two dimensional array
					// representing the excel data
					System.out.println("Value:" + value);
				}

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

	}