本文整理了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheetAt()
方法的一些代码示例,展示了HSSFWorkbook.getSheetAt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFWorkbook.getSheetAt()
方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFWorkbook
类名称:HSSFWorkbook
方法名:getSheetAt
[英]Get the HSSFSheet object at the given index.
[中]获取给定索引处的HSSFSheet对象。
代码示例来源:origin: org.apache.poi/poi
@Override
public EvaluationSheet getSheet(int sheetIndex) {
// TODO Cache these evaluation sheets so they aren't re-generated on every getSheet call
return new HSSFEvaluationSheet(_uBook.getSheetAt(sheetIndex));
}
@Override
代码示例来源:origin: org.apache.poi/poi
/**
* Gets the selected sheets (if more than one, Excel calls these a [Group]).
*
* @return indices of selected sheets
*/
public Collection<Integer> getSelectedTabs() {
Collection<Integer> indexes = new ArrayList<>();
int nSheets = _sheets.size();
for (int i=0; i<nSheets; i++) {
HSSFSheet sheet = getSheetAt(i);
if (sheet.isSelected()) {
indexes.add(i);
}
}
return Collections.unmodifiableCollection(indexes);
}
代码示例来源:origin: stackoverflow.com
HSSFWorkbook myWorkBook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream("E:/Project/SpringHibernet/MultiplexTicketBookingNew/web/excelSheets/Country.xlsx")));
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
System.out.println(mySheet.getRow(1).getCell(0));
代码示例来源:origin: org.apache.poi/poi
HSSFSheet sheet = wb.getSheetAt(i);
if(initDrawing) {
代码示例来源:origin: org.apache.poi/poi
/**
* Selects multiple sheets as a group. This is distinct from
* the 'active' sheet (which is the sheet with focus).
* Unselects sheets that are not in <code>indexes</code>.
*
* @param indexes Collection of sheets to select, the index is 0-based.
*/
public void setSelectedTabs(Collection<Integer> indexes) {
for (int index : indexes) {
validateSheetIndex(index);
}
// ignore duplicates
Set<Integer> set = new HashSet<>(indexes);
int nSheets = _sheets.size();
for (int i=0; i<nSheets; i++) {
boolean bSelect = set.contains(i);
getSheetAt(i).setSelected(bSelect);
}
// this is true only if all values in set were valid sheet indexes (between 0 and nSheets-1, inclusive)
short nSelected = (short) set.size();
workbook.getWindowOne().setNumSelectedTabs(nSelected);
}
代码示例来源:origin: org.apache.poi/poi
/**
* Selects a single sheet. This may be different to
* the 'active' sheet (which is the sheet with focus).
*/
@Override
public void setSelectedTab(int index) {
validateSheetIndex(index);
int nSheets = _sheets.size();
for (int i=0; i<nSheets; i++) {
getSheetAt(i).setSelected(i == index);
}
workbook.getWindowOne().setNumSelectedTabs((short)1);
}
代码示例来源:origin: org.apache.poi/poi
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook(xlsWorkbook);
InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
StringBuilder builder = new StringBuilder();
builder.append("<workbook>\n");
String tab = "\t";
if (!excludeWorkbookRecords && r != null) {
r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
for (EscherRecord record : escherRecords) {
builder.append(record.toXml(tab));
}
}
List<Integer> sheets = getSheetsIndexes(params, workbook);
for (Integer i : sheets) {
HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
if(p != null ) {
builder.append(tab).append("<sheet").append(i).append(">\n");
builder.append(p.getBoundAggregate().toXml(tab + "\t"));
builder.append(tab).append("</sheet").append(i).append(">\n");
}
}
builder.append("</workbook>\n");
fos.write(builder.toString().getBytes(StringUtil.UTF8));
fos.close();
workbook.close();
}
代码示例来源:origin: org.apache.poi/poi
/**
* Convenience method to set the active sheet. The active sheet is is the sheet
* which is currently displayed when the workbook is viewed in Excel.
* 'Selected' sheet(s) is a distinct concept.
*/
@Override
public void setActiveSheet(int index) {
validateSheetIndex(index);
int nSheets = _sheets.size();
for (int i=0; i<nSheets; i++) {
getSheetAt(i).setActive(i == index);
}
workbook.getWindowOne().setActiveSheetIndex(index);
}
代码示例来源:origin: stackoverflow.com
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row;
HSSFCell cell;
代码示例来源:origin: looly/hutool
/**
* 获取XLS工作簿指定sheet中图片列表
*
* @param workbook 工作簿{@link Workbook}
* @param sheetIndex sheet的索引
* @return 图片映射,键格式:行_列,值:{@link PictureData}
*/
private static Map<String, PictureData> getPicMapXls(HSSFWorkbook workbook, int sheetIndex) {
final Map<String, PictureData> picMap = new HashMap<>();
final List<HSSFPictureData> pictures = workbook.getAllPictures();
if (CollectionUtil.isNotEmpty(pictures)) {
final HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
HSSFClientAnchor anchor;
int pictureIndex;
for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
if (shape instanceof HSSFPicture) {
pictureIndex = ((HSSFPicture) shape).getPictureIndex() - 1;
anchor = (HSSFClientAnchor) shape.getAnchor();
picMap.put(StrUtil.format("{}_{}", anchor.getRow1(), anchor.getCol1()), pictures.get(pictureIndex));
}
}
}
return picMap;
}
代码示例来源:origin: looly/hutool
/**
* 获取XLS工作簿指定sheet中图片列表
*
* @param workbook 工作簿{@link Workbook}
* @param sheetIndex sheet的索引
* @return 图片映射,键格式:行_列,值:{@link PictureData}
*/
private static Map<String, PictureData> getPicMapXls(HSSFWorkbook workbook, int sheetIndex) {
final Map<String, PictureData> picMap = new HashMap<>();
final List<HSSFPictureData> pictures = workbook.getAllPictures();
if (CollectionUtil.isNotEmpty(pictures)) {
final HSSFSheet sheet = workbook.getSheetAt(sheetIndex);
HSSFClientAnchor anchor;
int pictureIndex;
for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren()) {
if (shape instanceof HSSFPicture) {
pictureIndex = ((HSSFPicture) shape).getPictureIndex() - 1;
anchor = (HSSFClientAnchor) shape.getAnchor();
picMap.put(StrUtil.format("{}_{}", anchor.getRow1(), anchor.getCol1()), pictures.get(pictureIndex));
}
}
}
return picMap;
}
代码示例来源:origin: org.apache.poi/poi
public void removeSheetAt(int index) {
validateSheetIndex(index);
boolean wasSelected = getSheetAt(index).isSelected();
boolean someOtherSheetIsStillSelected = false;
for (int i =0; i < nSheets; i++) {
if (getSheetAt(i).isSelected()) {
someOtherSheetIsStillSelected = true;
break;
代码示例来源:origin: pentaho/pentaho-kettle
void recalculateAllWorkbookFormulas() {
if ( data.wb instanceof XSSFWorkbook ) {
// XLSX needs full reevaluation
FormulaEvaluator evaluator = data.wb.getCreationHelper().createFormulaEvaluator();
for ( int sheetNum = 0; sheetNum < data.wb.getNumberOfSheets(); sheetNum++ ) {
Sheet sheet = data.wb.getSheetAt( sheetNum );
for ( Row r : sheet ) {
for ( Cell c : r ) {
if ( c.getCellType() == Cell.CELL_TYPE_FORMULA ) {
evaluator.evaluateFormulaCell( c );
}
}
}
}
} else if ( data.wb instanceof HSSFWorkbook ) {
// XLS supports a "dirty" flag to have excel recalculate everything when a sheet is opened
for ( int sheetNum = 0; sheetNum < data.wb.getNumberOfSheets(); sheetNum++ ) {
HSSFSheet sheet = ( (HSSFWorkbook) data.wb ).getSheetAt( sheetNum );
sheet.setForceFormulaRecalculation( true );
}
} else {
String forceRecalc = getVariable( STREAMER_FORCE_RECALC_PROP_NAME, "N" );
if ( "Y".equals( forceRecalc ) ) {
data.wb.setForceFormulaRecalculation( true );
}
}
}
代码示例来源:origin: org.apache.poi/poi
HSSFSheet sheet = _wb.getSheetAt(i);
if(sheet == null) { continue; }
代码示例来源:origin: org.apache.poi/poi
private void updateFormulasForShift(FormulaShifter formulaShifter) {
int sheetIndex = _workbook.getSheetIndex(this);
short externSheetIndex = _book.checkExternSheet(sheetIndex);
// update formulas on this sheet that point to rows which have been moved
_sheet.updateFormulasAfterCellShift(formulaShifter, externSheetIndex);
// update formulas on other sheets that point to rows that have been moved on this sheet
int nSheets = _workbook.getNumberOfSheets();
for (int i = 0; i < nSheets; i++) {
InternalSheet otherSheet = _workbook.getSheetAt(i).getSheet();
if (otherSheet == this._sheet) {
continue;
}
short otherExtSheetIx = _book.checkExternSheet(i);
otherSheet.updateFormulasAfterCellShift(formulaShifter, otherExtSheetIx);
}
_workbook.getWorkbook().updateNamesAfterCellShift(formulaShifter);
}
代码示例来源:origin: org.apache.poi/poi
HSSFSheet s = workbook.getSheetAt(sheetNum);
for (Row row : s) {
for (Cell cell : row) {
代码示例来源:origin: stackoverflow.com
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");
sheet = wb.getSheetAt(0);
for (Row myrow : sheet) {
for (Cell mycell : myrow) {
//set foreground color here
}
}
代码示例来源:origin: stackoverflow.com
HSSFSheet mySheet = myWorkBook.getSheetAt(0);
代码示例来源:origin: org.apache.poi/poi
HSSFSheet s = workbook.getSheetAt(sheetNum);
for (Row row : s) {
for (Cell cellI : row) {
HSSFSheet s = workbook.getSheetAt(sheetNum);
for (Row row : s) {
for (Cell cell : row) {
代码示例来源:origin: stackoverflow.com
public void addCoverType(HSSFWorkbook workbook, List<Book> books) {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = null;
//row 0 is the header (not automatically added by primefaces)
//add a fifth cell to each row
for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
sheet.getRow(i).createCell(4);
cell = sheet.getRow(i).getCell(4);
cell.setCellValue(book.get(i - 1).getCoverType());
}
log.debug("cover type added");
}
内容来源于网络,如有侵权,请联系作者删除!