本文整理了Java中org.apache.poi.ss.usermodel.Sheet.getSheetName()
方法的一些代码示例,展示了Sheet.getSheetName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sheet.getSheetName()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Sheet
类名称:Sheet
方法名:getSheetName
[英]Returns the name of this sheet
[中]返回此工作表的名称
代码示例来源:origin: pentaho/pentaho-kettle
public String getName() {
return sheet.getSheetName();
}
代码示例来源:origin: org.apache.poi/poi
@Override
public int hashCode() {
int hash = sheet.getSheetName().hashCode();
hash = 31 * hash + formattingIndex;
hash = 31 * hash + ruleIndex;
return hash;
}
代码示例来源:origin: org.apache.poi/poi
/**
* Lazy load validations by sheet, since reading the CT* types is expensive
*
* @param sheet The {@link Sheet} to load validations for.
* @return The {@link DataValidation}s for the sheet
*/
private List<? extends DataValidation> getValidations(Sheet sheet) {
List<? extends DataValidation> dvs = validations.get(sheet.getSheetName());
if (dvs == null && !validations.containsKey(sheet.getSheetName())) {
dvs = sheet.getDataValidations();
validations.put(sheet.getSheetName(), dvs);
}
return dvs;
}
代码示例来源:origin: pentaho/pentaho-kettle
public String getSheetName( int sheetNr ) {
Sheet sheet = (Sheet) getSheet( sheetNr );
if ( sheet == null ) {
return null;
}
return sheet.getSheetName();
}
}
代码示例来源:origin: org.apache.poi/poi
@Override
public String getFormulaString() {
return cellRangeAddress.formatAsString(sheet.getSheetName(), true);
}
代码示例来源:origin: looly/hutool
/**
* 获取表名列表
*
* @return 表名列表
* @since 4.0.3
*/
public List<String> getSheetNames() {
final int totalSheet = workbook.getNumberOfSheets();
List<String> result = new ArrayList<>(totalSheet);
for (int i = 0; i < totalSheet; i++) {
result.add(this.workbook.getSheetAt(i).getSheetName());
}
return result;
}
代码示例来源:origin: looly/hutool
/**
* 获取表名列表
*
* @return 表名列表
* @since 4.0.3
*/
public List<String> getSheetNames() {
final int totalSheet = workbook.getNumberOfSheets();
List<String> result = new ArrayList<>(totalSheet);
for (int i = 0; i < totalSheet; i++) {
result.add(this.workbook.getSheetAt(i).getSheetName());
}
return result;
}
代码示例来源:origin: org.apache.poi/poi
public static void main( String[] args ) throws IOException {
OutputStreamWriter osw = new OutputStreamWriter(System.out, Charset.defaultCharset());
PrintWriter pw = new PrintWriter(osw);
POIFSFileSystem fs = new POIFSFileSystem(new File(args[0]));
HSSFWorkbook wb = new HSSFWorkbook(fs);
try {
pw.println( "Drawing group:" );
wb.dumpDrawingGroupRecords(true);
int i = 1;
for (Sheet sheet : wb)
{
pw.println( "Sheet " + i + "(" + sheet.getSheetName() + "):" );
((HSSFSheet) sheet).dumpDrawingRecords(true, pw);
}
} finally {
wb.close();
fs.close();
}
}
}
代码示例来源:origin: org.apache.poi/poi
/**
* Defined as equal sheet name and formatting and rule indexes
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (! obj.getClass().equals(this.getClass())) {
return false;
}
final EvaluationConditionalFormatRule r = (EvaluationConditionalFormatRule) obj;
return getSheet().getSheetName().equalsIgnoreCase(r.getSheet().getSheetName())
&& getFormattingIndex() == r.getFormattingIndex()
&& getRuleIndex() == r.getRuleIndex();
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Create a pivot table using the Name range reference on sourceSheet, at the given position.
* If the source reference contains a sheet name, it must match the sourceSheet
* @param source location of pivot data
* @param position A reference to the top left cell where the pivot table will start
* @param sourceSheet The sheet containing the source data, if the source reference doesn't contain a sheet name
* @throws IllegalArgumentException if source references a sheet different than sourceSheet
* @return The pivot table
*/
@Beta
public XSSFPivotTable createPivotTable(final Name source, CellReference position, Sheet sourceSheet) {
if(source.getSheetName() != null && !source.getSheetName().equals(sourceSheet.getSheetName())) {
throw new IllegalArgumentException("The named range references another sheet than the "
+ "defined source sheet " + sourceSheet.getSheetName() + ".");
}
return createPivotTable(position, sourceSheet, wsSource -> wsSource.setName(source.getNameName()));
}
代码示例来源:origin: org.apache.poi/poi
final String sheetName = sheet.getSheetName();
List<EvaluationConditionalFormatRule> rules = formats.get(sheetName);
if (rules == null) {
代码示例来源:origin: org.apache.poi/poi
/**
* Per Excel Help, XSSF rule priority is sheet-wide, not just within the owning ConditionalFormatting object.
* This can be seen by creating 4 rules applying to two different ranges and examining the XML.
* <p>
* HSSF priority is based on definition/persistence order.
*
* @param o
* @return comparison based on sheet name, formatting index, and rule priority
*/
@Override
public int compareTo(EvaluationConditionalFormatRule o) {
int cmp = getSheet().getSheetName().compareToIgnoreCase(o.getSheet().getSheetName());
if (cmp != 0) {
return cmp;
}
final int x = getPriority();
final int y = o.getPriority();
// logic from Integer.compare()
cmp = Integer.compare(x, y);
if (cmp != 0) {
return cmp;
}
cmp = Integer.compare(getFormattingIndex(), o.getFormattingIndex());
if (cmp != 0) {
return cmp;
}
return Integer.compare(getRuleIndex(), o.getRuleIndex());
}
代码示例来源:origin: org.apache.poi/poi
public static CellReference getRef(Cell cell) {
return new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), false, false);
}
代码示例来源:origin: org.apache.poi/poi
/**
* checks if the given cell is part of the table. Includes checking that they are on the same sheet.
* @param cell
* @return true if the table and cell are on the same sheet and the cell is within the table range.
* @since 3.17 beta 1
* @see #contains(CellReference) (prefered, faster execution and handles undefined cells)
*/
default boolean contains(Cell cell) {
if (cell == null) return false;
return contains(new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}
代码示例来源:origin: org.apache.poi/poi
/**
* Calls {@link #getRange(Table, CellReference)}. Use that instead for performance.
* @param table
* @param cell
* @return default is unimplemented/null
* @see #getRange(Table, CellReference)
*/
public final CellRangeAddressBase getRange(Table table, Cell cell) {
if (cell == null) return null;
return getRange(table, new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Create a pivot table using the AreaReference range on sourceSheet, at the given position.
* If the source reference contains a sheet name, it must match the sourceSheet
* @param source location of pivot data
* @param position A reference to the top left cell where the pivot table will start
* @param sourceSheet The sheet containing the source data, if the source reference doesn't contain a sheet name
* @throws IllegalArgumentException if source references a sheet different than sourceSheet
* @return The pivot table
*/
@Beta
public XSSFPivotTable createPivotTable(final AreaReference source, CellReference position, Sheet sourceSheet) {
final String sourceSheetName = source.getFirstCell().getSheetName();
if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(sourceSheet.getSheetName())) {
throw new IllegalArgumentException("The area is referenced in another sheet than the "
+ "defined source sheet " + sourceSheet.getSheetName() + ".");
}
return createPivotTable(position, sourceSheet, wsSource -> {
final String[] firstCell = source.getFirstCell().getCellRefParts();
final String firstRow = firstCell[1];
final String firstCol = firstCell[2];
final String[] lastCell = source.getLastCell().getCellRefParts();
final String lastRow = lastCell[1];
final String lastCol = lastCell[2];
final String ref = firstCol+firstRow+':'+lastCol+lastRow; //or just source.formatAsString()
wsSource.setRef(ref);
});
}
代码示例来源:origin: org.apache.poi/poi
/**
* A range is returned only for the part of the table matching this enum instance and containing the given cell.
* Null is returned for all other cases, such as:
* <ul>
* <li>Cell on a different sheet than the table
* <li>Cell outside the table
* <li>this Enum part is not included in the table (i.e. no header/totals row)
* <li>this Enum is for a table part not yet implemented in POI, such as pivot table elements
* </ul>
* The returned range can be used to determine how style options may or may not apply to this cell.
* For example, {@link #wholeTable} borders only apply to the outer boundary of a table, while the
* rest of the styling, such as font and color, could apply to all the interior cells as well.
*
* @param table table to evaluate
* @param cell to evaluate
* @return range in the table representing this class of cells, if it contains the given cell, or null if not applicable.
* Stripe style types return only the stripe range containing the given cell, or null.
*/
public CellRangeAddressBase appliesTo(Table table, Cell cell) {
if (cell == null) return null;
return appliesTo(table, new CellReference(cell.getSheet().getSheetName(), cell.getRowIndex(), cell.getColumnIndex(), true, true));
}
代码示例来源:origin: org.apache.poi/poi
private void copyRange(CellRangeAddress sourceRange, int deltaX, int deltaY, Sheet sourceClone) { //NOSONAR, it's a bit complex but monolith method, does not make much sense to divide it
if(deltaX != 0)
horizontalFormulaShifter = FormulaShifter.createForColumnCopy(sourceSheet.getWorkbook().getSheetIndex(sourceSheet),
sourceSheet.getSheetName(), sourceRange.getFirstColumn(), sourceRange.getLastColumn(), deltaX, sourceSheet.getWorkbook().getSpreadsheetVersion());
if(deltaY != 0)
verticalFormulaShifter = FormulaShifter.createForRowCopy(sourceSheet.getWorkbook().getSheetIndex(sourceSheet),
sourceSheet.getSheetName(), sourceRange.getFirstRow(), sourceRange.getLastRow(), deltaY, sourceSheet.getWorkbook().getSpreadsheetVersion());
for(int rowNo = sourceRange.getFirstRow(); rowNo <= sourceRange.getLastRow(); rowNo++) {
Row sourceRow = sourceClone.getRow(rowNo); // copy from source copy, original source might be overridden in process!
for (int columnIndex = sourceRange.getFirstColumn(); columnIndex <= sourceRange.getLastColumn(); columnIndex++) {
Cell sourceCell = sourceRow.getCell(columnIndex);
if(sourceCell == null)
continue;
Row destRow = destSheet.getRow(rowNo + deltaY);
if(destRow == null)
destRow = destSheet.createRow(rowNo + deltaY);
Cell newCell = destRow.getCell(columnIndex + deltaX);
if(newCell != null)
newCell.setCellType(sourceCell.getCellType());
else newCell = destRow.createCell(columnIndex + deltaX, sourceCell.getCellType());
cloneCellContent(sourceCell, newCell, null);
if(newCell.getCellType() == CellType.FORMULA)
adjustCellReferencesInsideFormula(newCell, destSheet, deltaX, deltaY);
}
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void forcesToRecalculate_Hssf() throws Exception {
data.wb = new HSSFWorkbook();
data.wb.createSheet( "sheet1" );
data.wb.createSheet( "sheet2" );
step.recalculateAllWorkbookFormulas();
if ( !data.wb.getForceFormulaRecalculation() ) {
int sheets = data.wb.getNumberOfSheets();
for ( int i = 0; i < sheets; i++ ) {
Sheet sheet = data.wb.getSheetAt( i );
assertTrue( "Sheet #" + i + ": " + sheet.getSheetName(), sheet.getForceFormulaRecalculation() );
}
}
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
cacheSource.setType(STSourceType.WORKSHEET);
CTWorksheetSource worksheetSource = cacheSource.addNewWorksheetSource();
worksheetSource.setSheet(sourceSheet.getSheetName());
setDataSheet(sourceSheet);
内容来源于网络,如有侵权,请联系作者删除!