List of usage examples for org.apache.poi.ss.usermodel Workbook getName
Name getName(String name);
From source file:com.dituiba.excel.DefaultValidateAdapter.java
License:Apache License
/** * ??/*ww w . j av a 2s .c om*/ * @param config * @param sheet * @param columnIndex * @param valueSet */ protected void createDicCodeSheet(DicValidateConfig config, Sheet sheet, int columnIndex, Set<String> valueSet) { Workbook workbook = sheet.getWorkbook(); Sheet codeSheet = workbook.getSheet(DICCODE_SHEET_NAME); if (codeSheet == null) { log.debug("?Sheet?Sheet"); codeSheet = workbook.createSheet(DICCODE_SHEET_NAME); } int codeIndex = config.columnName() - 'A'; log.debug("codeIndex{}", codeIndex); if (codeSheet.getRow(0) == null || codeSheet.getRow(0).getCell(codeIndex) == null) { log.debug("????"); int i = 0; for (String dic : valueSet) { Row row = codeSheet.getRow(i); if (row == null) row = codeSheet.createRow(i); Cell cell = row.createCell(codeIndex); cell.setCellValue(dic); i++; } } else { log.debug("????"); } Name name = workbook.getName(config.columnName() + ""); if (name == null || name.isDeleted()) { log.debug("?Name?Name"); name = workbook.createName(); name.setNameName(config.columnName() + ""); } name.setRefersToFormula(DICCODE_SHEET_NAME + "!$" + config.columnName() + "$1:$" + config.columnName() + "$" + valueSet.size()); DVConstraint constraint = DVConstraint.createFormulaListConstraint(name.getNameName()); CellRangeAddressList addressList = new CellRangeAddressList(BaseExcelService.START_ROW, Short.MAX_VALUE, columnIndex, columnIndex); HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint); workbook.setSheetHidden(workbook.getSheetIndex(DICCODE_SHEET_NAME), Workbook.SHEET_STATE_VERY_HIDDEN); setValidationTip(validation, config); sheet.addValidationData(validation); log.debug("??"); }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.CommentsAnalysisReportGenerator.java
License:Apache License
/** * Create the report sheets//w w w.ja v a2 s . co m * * @throws Exception */ private void createReport(Workbook p_workbook, Job p_job, List<GlobalSightLocale> p_targetLocales, String p_dateFormat) throws Exception { List<GlobalSightLocale> jobTL = ReportHelper.getTargetLocals(p_job); for (GlobalSightLocale trgLocale : p_targetLocales) { if (!jobTL.contains(trgLocale)) continue; String srcLang = p_job.getSourceLocale().getDisplayName(uiLocale); String trgLang = trgLocale.getDisplayName(uiLocale); // Create One Report Sheet/Tab Sheet sheet = null; if (isCombineAllJobs && p_workbook.getSheet(trgLocale.toString()) != null) { sheet = p_workbook.getSheet(trgLocale.toString()); } else { sheet = p_workbook.createSheet(trgLocale.toString()); sheet.protectSheet(""); // Add Title addTitle(p_workbook, sheet); // Add Locale Pair Header addLanguageHeader(p_workbook, sheet); // Add Segment Header addSegmentHeader(p_workbook, sheet); // Insert Language Data writeLanguageInfo(p_workbook, sheet, srcLang, trgLang); } // Create Name Areas for drop down list. if (p_workbook.getName(CATEGORY_FAILURE_DROP_DOWN_LIST) == null) { createCategoryFailureNameArea(p_workbook); } // Insert Segment Data if (isCombineAllJobs) { Integer row = null; if (rowsMap.get(trgLang) == null) { row = writeSegmentInfo(p_workbook, sheet, p_job, trgLocale, p_dateFormat, SEGMENT_START_ROW); } else { row = writeSegmentInfo(p_workbook, sheet, p_job, trgLocale, p_dateFormat, rowsMap.get(trgLang)); } rowsMap.put(trgLang, row); } else { writeSegmentInfo(p_workbook, sheet, p_job, trgLocale, p_dateFormat, SEGMENT_START_ROW); } } }
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.ImplementedCommentsCheckReportGenerator.java
License:Apache License
/** * Create the report sheets// ww w . j a v a 2s .c om * * @throws Exception */ private void createReport(Workbook p_workbook, Job p_job, List<GlobalSightLocale> p_targetLocales, String p_dateFormat) throws Exception { List<GlobalSightLocale> jobTL = ReportHelper.getTargetLocals(p_job); for (GlobalSightLocale trgLocale : p_targetLocales) { if (!jobTL.contains(trgLocale)) continue; String srcLang = p_job.getSourceLocale().getDisplayName(uiLocale); String trgLang = trgLocale.getDisplayName(uiLocale); // Create One Report Sheet/Tab Sheet sheet = null; if (p_workbook.getSheet(trgLocale.toString()) != null) { sheet = p_workbook.getSheet(trgLocale.toString()); } else { sheet = p_workbook.createSheet(trgLocale.toString()); sheet.protectSheet(""); // Add Title addTitle(p_workbook, sheet); // Add Locale Pair Header addLanguageHeader(p_workbook, sheet); // Add Segment Header addSegmentHeader(p_workbook, sheet); // Insert Language Data writeLanguageInfo(p_workbook, sheet, srcLang, trgLang); } // Create Name Areas for drop down list. if (p_workbook.getName(CATEGORY_FAILURE_DROP_DOWN_LIST) == null) { createCategoryFailureNameArea(p_workbook); } writeSegmentInfo(p_workbook, sheet, p_job, trgLocale, p_dateFormat, SEGMENT_START_ROW); } }
From source file:nu.mine.kino.jenkins.plugins.projectmanagement.utils.PMUtils.java
License:Open Source License
public static Date getBaseDateFromExcelWithPoi(File file) { InputStream in = null;/*from w ww . j av a 2 s . c o m*/ try { in = new FileInputStream(file); Workbook workbook = WorkbookFactory.create(in); Sheet sheet = workbook.getSheetAt(0); Name name = workbook.getName("??"); CellReference cellRef = new CellReference(name.getRefersToFormula()); Row row = sheet.getRow(cellRef.getRow()); Cell baseDateCell = row.getCell(cellRef.getCol()); // System.out.println("cellt:" // + PoiUtil.isCellDateFormatted(baseDateCell)); Date baseDate = baseDateCell.getDateCellValue(); return baseDate; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) try { in.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:nu.mine.kino.projects.utils.POI2Test.java
License:Open Source License
private void expandRange(Workbook workbook, String sheetName, String dataName, int dataCount) { // OwZ//from w ww. j a v a 2 s . co m Sheet sheet = workbook.getSheet(sheetName); final Name DATA_AREA = workbook.getName(dataName); final AreaReference areaReference = new AreaReference(DATA_AREA.getRefersToFormula()); // final CellReference firstCell = areaReference.getFirstCell(); final CellReference lastCell = areaReference.getLastCell(); // System.out.printf("??sIndex %s\n", firstCell.getRow()); System.out.printf("??I?sIndex %s\n", lastCell.getRow()); sheet.shiftRows(lastCell.getRow(), lastCell.getRow(), dataCount); }
From source file:nu.mine.kino.projects.utils.ProjectUtils.java
License:Open Source License
public static Date createBaseDate(Workbook workbook, Sheet sheet) { Date baseDate;//www . j a va 2s .c o m Name name = workbook.getName("??"); CellReference cellReference = new CellReference(name.getRefersToFormula()); Cell baseDateCell = sheet.getRow(cellReference.getRow()).getCell(cellReference.getCol()); baseDate = PoiUtils.getDate(baseDateCell); return baseDate; }
From source file:org.formulacompiler.spreadsheet.internal.excel.xls.loader.ExcelXLSLoader.java
License:Open Source License
private Cell getCellByName(String _name, Workbook _workbook, BaseSpreadsheet _spreadsheet) { final Name name = _workbook.getName(_name); if (name == null) return null; if (name.isFunctionName()) return null; final String cellRangeAddress = name.getRefersToFormula(); final ExpressionParser parser = new SpreadsheetExpressionParserA1OOXML(cellRangeAddress, _spreadsheet); try {/* w w w .ja va2 s . co m*/ final CellRange range = (CellRange) parser.rangeOrCellRefA1(); if (!(range instanceof CellIndex)) { return null; } final CellIndex cellIndex = (CellIndex) range; final int sheetIndex = cellIndex.getSheetIndex(); final int rowIndex = cellIndex.getRowIndex(); final int columnIndex = cellIndex.getColumnIndex(); return _workbook.getSheetAt(sheetIndex).getRow(rowIndex).getCell(columnIndex); } catch (ParseException e) { // Ignore all non 'named range' names return null; } }
From source file:org.jreserve.gui.poi.ExcelUtil.java
License:Open Source License
public static CellReference getCellReference(Workbook wb, String ref) { Name name = wb.getName(ref); if (name != null) ref = name.getRefersToFormula(); if (ref.indexOf(':') > 0) { AreaReference aRef = new AreaReference(ref); return aRef.getFirstCell(); } else {// w w w . j av a2s.c om return new CellReference(ref); } }