org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheet()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(315)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheet()方法的一些代码示例,展示了HSSFWorkbook.getSheet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFWorkbook.getSheet()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFWorkbook
类名称:HSSFWorkbook
方法名:getSheet

HSSFWorkbook.getSheet介绍

[英]Get sheet with the given name (case insensitive match)
[中]获取具有给定名称的工作表(不区分大小写匹配)

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void testProtectSheet() throws Exception {
 step.protectSheet( wb.getSheet( SHEET_NAME ), "aa" );
 assertTrue( wb.getSheet( SHEET_NAME ).getProtect() );
}

代码示例来源:origin: org.databene/databene-webdecs

private static HSSFSheet sheet(String uri, String sheetName) throws IOException {
  HSSFWorkbook workbook = new HSSFWorkbook(IOUtil.getInputStreamForURI(uri));
  HSSFSheet sheet = sheetName != null ? workbook.getSheet(sheetName) : workbook.getSheetAt(0);
  if (sheet == null)
    throw new IllegalArgumentException("Sheet not found in file " + uri + ": " + sheetName);
  return sheet;
}

代码示例来源:origin: stackoverflow.com

File destFile = new File("/test.xls");
FileInputStream fileStream = new FileInputStream(destFile);
POIFSFileSystem fsPoi = new POIFSFileSystem(fileStream);

HSSFWorkbook workbook = new HSSFWorkbook(fsPoi);

int index = 0;

HSSFSheet sheet = workbook.getSheet("Setup");
if(sheet != null)   {
  index = workbook.getSheetIndex(sheet);
  workbook.removeSheetAt(index);
}
workbook.createSheet("Setup");
FileOutputStream output = new FileOutputStream(destFile);
workbook.write(output);
output.close();

代码示例来源:origin: stackoverflow.com

FileInputStream input=new FileInputStream(new File("../../TestCase.xls"));
HSSFWorkbook workbook=new HSSFWorkbook(input);
HSSFSheet sheet=workbook.getSheet("KeywordFramework");
System.out.println("i am in");

代码示例来源:origin: de.adorsys.sts/sts-worksheet-loader

private void updateLogin(HSSFWorkbook workbook) {
    HSSFSheet sheet = workbook.getSheet("Login");
    if (sheet == null)
      return;

    Iterator<Row> rowIterator = sheet.rowIterator();
    rowIterator.next();

    while (rowIterator.hasNext()) {
      Row row = rowIterator.next();
      loginLoader.update(row);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public extractDataFromXls(String fileName, sheetName) throws FileNotFoundException {
   FileInputStream fileInputStream = new FileInputStream(fileName);
   HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
   HSSFSheet worksheet = workbook.getSheet(sheetName);
   HSSFRow row = worksheet.getRow(0);
   for (short i = 0; i < 5; i++) {
     HSSFCell cell = row.getCell(i);
     String value = cell.getStringCellValue();
     System.out.println(value);
   }
 }

代码示例来源:origin: stackoverflow.com

FileInputStream fileInputStream = new FileInputStream(fileName);
   HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
   HSSFSheet worksheet = workbook.getSheet(sheetName);
   Iterator<Row> it = worksheet.rowIterator();
   while(it.hasNext()){
     HSSFRow r = (HSSFRow) it.next();
     Iterator<Cell> it1=r.cellIterator();
     while(it1.hasNext()){
       HSSFCell cell = (HSSFCell)it1.next();
       System.out.println("Row: "+cell.getRowIndex()+" ,Column: "+cell.getColumnIndex());
       System.out.println(cell);
     }
     System.out.println();
   }
 } catch (FileNotFoundException e) {
   e.printStackTrace();
 } catch (IOException e) {
   e.printStackTrace();
 }

代码示例来源:origin: stackoverflow.com

HSSFWorkbook book1 = new HSSFWorkbook();
    HSSFSheet sheet = book1.getSheet("sheetName");
    int rowIndex=sheet.getLastRowNum()+1;//
    int columnIndex = sheet.getRow(sheet.getLastRowNum()).getPhysicalNumberOfCells()

代码示例来源:origin: com.haulmont.yarg/yarg

public static HSSFSheet getTemplateSheetForRangeName(HSSFWorkbook workbook, String rangeName) {
    int rangeNameIdx = workbook.getNameIndex(rangeName);
    if (rangeNameIdx == -1) return null;

    HSSFName aNamedRange = workbook.getNameAt(rangeNameIdx);
    String sheetName = aNamedRange.getSheetName();
    return workbook.getSheet(sheetName);
  }
}

代码示例来源:origin: org.databene/databene-formats

private HSSFSheet getOrCreateSheet(E bean, String sheetName) {
  // create file
  if (workbook == null)
    createWorkbook();
  HSSFSheet sheet = workbook.getSheet(sheetName);
  if (sheet == null) {
    sheet = workbook.createSheet(sheetName);
    writeHeaderRow(bean, sheet);
  }
  return sheet;
}

代码示例来源:origin: cuba-platform/yarg

public static HSSFSheet getTemplateSheetForRangeName(HSSFWorkbook workbook, String rangeName) {
    int rangeNameIdx = workbook.getNameIndex(rangeName);
    if (rangeNameIdx == -1) return null;

    HSSFName aNamedRange = workbook.getNameAt(rangeNameIdx);
    String sheetName = aNamedRange.getSheetName();
    return workbook.getSheet(sheetName);
  }
}

代码示例来源:origin: stackoverflow.com

FileInputStream file = new FileInputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls"));        
     HSSFWorkbook workbook1 = new HSSFWorkbook(file);
     HSSFSheet sheet1 = workbook1.getSheet("Comparatif");
     //Get first sheet from the workbook
     HSSFSheetConditionalFormatting cf =sheet1.getSheetConditionalFormatting();
     int i;
     i=17;
     for(;i<=ligne;i++){
     HSSFConditionalFormattingRule cfrole=cf.createConditionalFormattingRule(ComparisonOperator.NOT_EQUAL,"$C$"+i ); 
     HSSFPatternFormatting fill_pattern = cfrole.createPatternFormatting();
     fill_pattern.setFillBackgroundColor(IndexedColors.YELLOW.index);
     CellRangeAddress[] my_data_range = {CellRangeAddress.valueOf("B"+i+":B"+i)};
     cf.addConditionalFormatting(my_data_range,cfrole);
     }
     for(i=17;i<=ligne;i++){
       HSSFConditionalFormattingRule cfrole=cf.createConditionalFormattingRule(ComparisonOperator.NOT_EQUAL,"$B$"+i ); 
       HSSFPatternFormatting fill_pattern = cfrole.createPatternFormatting();
       fill_pattern.setFillBackgroundColor(IndexedColors.YELLOW.index);
       CellRangeAddress[] my_data_range = {CellRangeAddress.valueOf("C"+i+":C"+i)};
       cf.addConditionalFormatting(my_data_range,cfrole);
       }
 FileOutputStream out = new FileOutputStream(new File("D://DEQ//"+selectitem.getRefDeq()+"//Comparatif.xls"));
     workbook1.write(out);
     out.close();

代码示例来源:origin: Impetus/jumbune

/**
 * Adds a sheet in the Workbook
 * @param worksheet the worksheet
 * @param sheetName name of sheet
 */
public static void addSheet(Worksheet worksheet, String sheetName) {
  HSSFWorkbook workbook = null;
  HSSFSheet sheet= null;
  String classSymbol = null;
  
  workbook = worksheet.getWorkbook();
  if (workbook.getSheet(sheetName) != null) {
    return;
  }
  sheet = workbook.createSheet(sheetName);
  
  Map<String, HSSFSheet> sheets = worksheet.getSheets();
  Map<String, String> sheetSymbol = worksheet.getSheetSymbol();
  
  classSymbol = sheetSymbol.get(sheetName);
   if ( classSymbol != null) {
     sheets.put(classSymbol, sheet);
   } else {
     sheets.put(sheetName, sheet);
   }
}

代码示例来源:origin: stackoverflow.com

FileInputStream file = new FileInputStream(new File("/output.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheet("Sheet1");

代码示例来源:origin: us.ihmc/ihmc-avatar-interfaces

public ReachabilityMapFileLoader(File fileToLoad, String robotName, RigidBodyBasics rootBody, HumanoidReferenceFrames referenceFrames)
{
 try
 {
   fileSystem = new NPOIFSFileSystem(fileToLoad);
   workBookToLoad = new HSSFWorkbook(fileSystem.getRoot(), true);
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }
 HSSFSheet descriptionSheet = workBookToLoad.getSheet("Description");
 checkRobotMatchesData(robotName, rootBody, descriptionSheet);
 ReferenceFrame gridFrame = createGridReferenceFrame(rootBody, referenceFrames, descriptionSheet);
 loadedGrid = createGrid(descriptionSheet, gridFrame);
 loadData();
 close();
}

代码示例来源:origin: us.ihmc/DarpaRoboticsChallenge

public ReachabilityMapFileLoader(File fileToLoad, String robotName, RigidBody rootBody, HumanoidReferenceFrames referenceFrames)
{
 try
 {
   fileSystem = new NPOIFSFileSystem(fileToLoad);
   workBookToLoad = new HSSFWorkbook(fileSystem.getRoot(), true);
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }
 HSSFSheet descriptionSheet = workBookToLoad.getSheet("Description");
 checkRobotMatchesData(robotName, rootBody, descriptionSheet);
 ReferenceFrame gridFrame = createGridReferenceFrame(rootBody, referenceFrames, descriptionSheet);
 loadedGrid = createGrid(descriptionSheet, gridFrame);
 loadData();
 close();
}

代码示例来源:origin: paypal/SeLion

public void generateRep(HSSFWorkbook wb, String sheetName, List<BaseReport<?>> lstReports) {
  logger.entering(new Object[] { wb, sheetName, lstReports });
  int rowNum = 0;
  int iColStart = startColNum;
  HSSFSheet sheet;
  if (wb.getSheet(sheetName) == null) {
    sheet = wb.createSheet(sheetName);
  } else {
    sheet = wb.getSheet(sheetName);
    rowNum = sheet.getPhysicalNumberOfRows() + 2;
  }
  for (BaseReport<?> br : lstReports) {
    br.createReportName(sheet, rowNum++, iColStart, Styles.getHeadingStyle());
    br.createTitles(sheet, rowNum++, iColStart, Styles.getSubHeading2Style());
    rowNum = br.fillData(sheet, rowNum++, Styles.getStyleBorderThinCenter());
    rowNum += 3;
  }
  logger.exiting();
}

代码示例来源:origin: us.ihmc/DarpaRoboticsChallenge

private void loadData()
{
 HSSFRow currentRow;
 HSSFSheet currentDataSheet;
 int currentDataSheetNameIndex = 1;
 currentDataSheet = workBookToLoad.getSheet("Data" + currentDataSheetNameIndex++);
 while (currentDataSheet != null)
 {
   int currentRowIndex = 1;
   currentRow = currentDataSheet.getRow(currentRowIndex++);
   int cellIndex = 0;
   while (currentRow != null)
   {
    cellIndex = 0;
    int xIndex = (int) currentRow.getCell(cellIndex++).getNumericCellValue();
    int yIndex = (int) currentRow.getCell(cellIndex++).getNumericCellValue();
    int zIndex = (int) currentRow.getCell(cellIndex++).getNumericCellValue();
    int rayIndex = (int) currentRow.getCell(cellIndex++).getNumericCellValue();
    int rotationAroundRayIndex = (int) currentRow.getCell(cellIndex++).getNumericCellValue();
    loadedGrid.registerReachablePose(xIndex, yIndex, zIndex, rayIndex, rotationAroundRayIndex);
    currentRow = currentDataSheet.getRow(currentRowIndex++);
   }
   currentDataSheet = workBookToLoad.getSheet("Data" + currentDataSheetNameIndex++);
 }
}

代码示例来源:origin: org.drools/drools-scorecards

@Override
public List<ScorecardError>  parseFile(InputStream inStream, String worksheetName) throws ScorecardParseException {
  try {
    excelDataCollector = new XLSEventDataCollector();
    excelDataCollector.setParser(this);
    HSSFWorkbook workbook = new HSSFWorkbook(inStream);
    HSSFSheet worksheet = workbook.getSheet(worksheetName);
    if (worksheet != null) {
      currentWorksheet = worksheet;
      excelDataCollector.sheetStart(worksheetName);
      excelDataCollector.setMergedRegionsInSheet(getMergedCellRangeList(worksheet));
      processSheet(worksheet);
      excelDataCollector.sheetComplete();
      parseErrors = excelDataCollector.getParseErrors();
      scorecard = excelDataCollector.getScorecard();
    } else {
      throw new ScorecardParseException("No worksheet found with name '" + worksheetName + "'.");
    }
  } catch (IOException e) {
    throw new ScorecardParseException(e);
  }
  return parseErrors;
}

代码示例来源:origin: bedatadriven/activityinfo

/**
   * Exporter obey following rules:
   * - only activities of selected DB
   * - number of sheets must be the same as number of activities
   */
  @Test
  public void numberOfSheets() {

    Filter filter = new Filter();
    filter.addRestriction(DimensionType.Database, PEAR_DB);

    SiteExporter exporter = new SiteExporter(new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XY"));
    exporter.buildExcelWorkbook(filter);

    assertEquals(exporter.getBook().getNumberOfSheets(), 2);
    assertNotNull(exporter.getBook().getSheet("NFI"));
  }
}

相关文章

HSSFWorkbook类方法