當前位置: 首頁>>代碼示例>>Java>>正文


Java HSSFWorkbook.getNumberOfSheets方法代碼示例

本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.getNumberOfSheets方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFWorkbook.getNumberOfSheets方法的具體用法?Java HSSFWorkbook.getNumberOfSheets怎麽用?Java HSSFWorkbook.getNumberOfSheets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.hssf.usermodel.HSSFWorkbook的用法示例。


在下文中一共展示了HSSFWorkbook.getNumberOfSheets方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readXls

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
 * Read the Excel 2003-2007
 * 
 * @param path
 *            the path of the Excel
 * @return
 * @throws IOException
 */
public static String readXls(String path) throws IOException {
	InputStream is = new FileInputStream(path);
	HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
	StringBuffer sb = new StringBuffer("");
	// Read the Sheet
	for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
		HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
		if (hssfSheet == null) {
			continue;
		}
		// Read the Row
		for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
			HSSFRow hssfRow = hssfSheet.getRow(rowNum);
			if (hssfRow != null) {
				HSSFCell no = hssfRow.getCell(0);
				HSSFCell name = hssfRow.getCell(1);
				sb.append(no + ":" + name);
				sb.append(";");
			}
		}
	}
	return sb.toString().substring(0, sb.toString().length() - 1);
}
 
開發者ID:wufeisoft,項目名稱:data,代碼行數:32,代碼來源:ReadExcelUtil.java

示例2: readExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void readExcel(String filePth) throws Exception {
	InputStream is = new FileInputStream(filePth);
	//創建工作薄
	//XSSFWorkbook hwb = new XSSFWorkbook(is);
	HSSFWorkbook hwb = new HSSFWorkbook(new POIFSFileSystem(is));
	//得到sheet
	for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
		HSSFSheet sheet = hwb.getSheetAt(i);
		int rows = sheet.getPhysicalNumberOfRows();
		//遍曆每一行
		for (int j = 0; j < rows; j++) {
			HSSFRow hr = sheet.getRow(j);
			Iterator<?> it = hr.iterator();
			while(it.hasNext()){
				String context = it.next().toString();
				System.out.println(context);
			}
		}
	}
	hwb.close();
}
 
開發者ID:tank2140896,項目名稱:JavaWeb,代碼行數:22,代碼來源:FileUtil.java

示例3: countSheetFromTemplate

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private int countSheetFromTemplate(final HSSFWorkbook workbook, final ERDiagram diagram) {
    int count = 0;

    for (int sheetNo = 0; sheetNo < workbook.getNumberOfSheets(); sheetNo++) {
        final String templateSheetName = workbook.getSheetName(sheetNo);

        final AbstractSheetGenerator sheetGenerator = getSheetGenerator(templateSheetName);

        if (sheetGenerator != null) {
            count += sheetGenerator.count(diagram);

        } else {
            count++;
        }
    }

    if (exportExcelSetting.isPutERDiagramOnExcel()) {
        count += 1;
    }

    return count;
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:23,代碼來源:ExportToExcelManager.java

示例4: countSheetFromTemplate

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private int countSheetFromTemplate(HSSFWorkbook workbook, ERDiagram diagram) {
	int count = 0;

	for (int sheetNo = 0; sheetNo < workbook.getNumberOfSheets(); sheetNo++) {
		String templateSheetName = workbook.getSheetName(sheetNo);

		AbstractSheetGenerator sheetGenerator = this
				.getSheetGenerator(templateSheetName);

		if (sheetGenerator != null) {
			count += sheetGenerator.count(diagram);

		} else {
			count++;
		}
	}

	if (this.exportExcelSetting.isPutERDiagramOnExcel()) {
		count += 1;
	}

	return count;
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:24,代碼來源:ExportToExcelManager.java

示例5: working

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void working(InputStream stream) throws Exception {
    HSSFWorkbook workbook = new HSSFWorkbook(stream);
    int sheetNumber = workbook.getNumberOfSheets();
    for (int i = 0; i < sheetNumber; i++) {
        createTable(workbook.getSheetAt(i));
    }
    database.close();
}
 
開發者ID:androidmads,項目名稱:SQLite2XL,代碼行數:9,代碼來源:ExcelToSQLite.java

示例6: xlsToHtml

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void xlsToHtml() throws Throwable {
	FileOutputStream output = new FileOutputStream(new File(htmlPath));
	StringBuffer htmlHeaderSB = new StringBuffer();
	htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
			+ "xmlns='http://www.w3.org/TR/REC-html40'>");
	htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
			+ "</head><body>");
	output.write(htmlHeaderSB.toString().getBytes());
	HSSFSheet sheet;
	HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 獲整個Excel
	for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
		if (workbook.getSheetAt(sheetIndex) != null) {
			sheet = workbook.getSheetAt(sheetIndex);// 獲得不為空的這個sheet
			if (sheet != null) {
				int firstRowNum = sheet.getFirstRowNum(); // 第一行
				int lastRowNum = sheet.getLastRowNum(); // 最後一行
				// 構造Table
				output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
						+ "border-collapse:collapse;\">").getBytes());
				for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
					if (sheet.getRow(rowNum) != null) {// 如果行不為空,
						HSSFRow row = sheet.getRow(rowNum);
						short firstCellNum = row.getFirstCellNum(); // 該行的第一個單元格
						short lastCellNum = row.getLastCellNum(); // 該行的最後一個單元格
						int height = (int) (row.getHeight() / 15.625); // 行的高度
						output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
								+ "margin:2px 0 2px 0;\">").getBytes());
						for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循環該行的每一個單元格
							HSSFCell cell = row.getCell(cellNum);
							if (cell != null) {
								if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
									StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
											+ "margin:2px 0 2px 0; ");
									HSSFCellStyle cellStyle = cell.getCellStyle();
									HSSFPalette palette = workbook.getCustomPalette(); // 類HSSFPalette用於求顏色的國際標準形式
									HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
									HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
									String bgColor = convertToStardColor(hColor);// 背景顏色
									short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字體粗細
									short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字體大小
									String fontColor = convertToStardColor(hColor2); // 字體顏色
									if (bgColor != null && !"".equals(bgColor.trim())) {
										tdStyle.append(" background-color:");
										tdStyle.append(bgColor);
										tdStyle.append("; ");
									}
									if (fontColor != null && !"".equals(fontColor.trim())) {
										tdStyle.append(" color:");
										tdStyle.append(fontColor);
										tdStyle.append("; ");
									}
									tdStyle.append(" font-weight:");
									tdStyle.append(boldWeight);
									tdStyle.append("; ");
									tdStyle.append(" font-size: ");
									tdStyle.append(fontHeight);
									tdStyle.append("%;");
									output.write((tdStyle + "\"").getBytes());

									int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
									int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合並的列(solspan)
									int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合並的行(rowspan)
									String align = convertAlignToHtml(cellStyle.getAlignment()); //
									String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());

									output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
									output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
									output.write((">" + getCellValue(cell) + "</td>").getBytes());
								}
							}
						}
						output.write("</tr>".getBytes());
					}
				}
				output.write(("</table>").getBytes());
			}
		}
	}
	output.write(("</body></html>").getBytes());
	output.close();
}
 
開發者ID:MobClub,項目名稱:BBSSDK-for-Android,代碼行數:82,代碼來源:OfficeConverter.java

示例7: initSheetNameMap

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void initSheetNameMap(final HSSFWorkbook workbook) {
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        final String sheetName = workbook.getSheetName(i);
        sheetNameMap.put(sheetName.toUpperCase(), 0);
    }
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:7,代碼來源:ExportToExcelManager.java

示例8: createSheetFromTemplate

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void createSheetFromTemplate(final ProgressMonitor monitor, final HSSFWorkbook workbook, final ERDiagram diagram, final boolean useLogicalNameAsSheetName) throws InterruptedException {
    initSheetNameMap(workbook);

    int originalSheetNum = workbook.getNumberOfSheets();

    int sheetIndexSheetNo = -1;

    while (originalSheetNum > 0) {
        final String templateSheetName = workbook.getSheetName(0);

        final AbstractSheetGenerator sheetGenerator = getSheetGenerator(templateSheetName);

        if (sheetGenerator != null) {
            sheetGenerator.generate(monitor, workbook, 0, useLogicalNameAsSheetName, sheetNameMap, sheetObjectMap, diagram, loopDefinitionMap);
            workbook.removeSheetAt(0);

        } else {
            if (!isExcludeTarget(templateSheetName)) {
                moveSheet(workbook, 0);
                final HSSFSheet sheet = workbook.getSheetAt(workbook.getNumberOfSheets() - 1);

                sheetObjectMap.put(templateSheetName, new StringObjectModel(templateSheetName));

                if (pictureSheetGenerator != null) {
                    pictureSheetGenerator.setImage(workbook, sheet);
                }

                if (sheetIndexSheetGenerator.getTemplateSheetName().equals(templateSheetName)) {
                    sheetIndexSheetNo = workbook.getNumberOfSheets() - originalSheetNum;

                    String name = sheetIndexSheetGenerator.getSheetName();

                    name = AbstractSheetGenerator.decideSheetName(name, sheetNameMap);

                    monitor.subTaskWithCounter(name);

                    workbook.setSheetName(workbook.getNumberOfSheets() - 1, name);
                } else {
                    monitor.subTaskWithCounter(sheet.getSheetName());
                }

            } else {
                monitor.subTaskWithCounter("Removing template sheet");
                workbook.removeSheetAt(0);
            }

            monitor.worked(1);
        }

        originalSheetNum--;
    }

    if (sheetIndexSheetNo != -1) {
        sheetIndexSheetGenerator.generate(monitor, workbook, sheetIndexSheetNo, useLogicalNameAsSheetName, sheetNameMap, sheetObjectMap, diagram, loopDefinitionMap);
    }
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:57,代碼來源:ExportToExcelManager.java

示例9: initSheetNameMap

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void initSheetNameMap(HSSFWorkbook workbook) {
	for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
		String sheetName = workbook.getSheetName(i);
		this.sheetNameMap.put(sheetName.toUpperCase(), 0);
	}
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:7,代碼來源:ExportToExcelManager.java

示例10: createSheetFromTemplate

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void createSheetFromTemplate(ProgressMonitor monitor,
		HSSFWorkbook workbook, ERDiagram diagram,
		boolean useLogicalNameAsSheetName) throws InterruptedException {
	this.initSheetNameMap(workbook);

	int originalSheetNum = workbook.getNumberOfSheets();

	int sheetIndexSheetNo = -1;

	while (originalSheetNum > 0) {
		String templateSheetName = workbook.getSheetName(0);

		AbstractSheetGenerator sheetGenerator = this
				.getSheetGenerator(templateSheetName);

		if (sheetGenerator != null) {
			sheetGenerator.generate(monitor, workbook, 0,
					useLogicalNameAsSheetName, this.sheetNameMap,
					this.sheetObjectMap, diagram, loopDefinitionMap);
			workbook.removeSheetAt(0);

		} else {
			if (!isExcludeTarget(templateSheetName)) {
				moveSheet(workbook, 0);
				HSSFSheet sheet = workbook.getSheetAt(workbook
						.getNumberOfSheets() - 1);

				this.sheetObjectMap.put(templateSheetName,
						new StringObjectModel(templateSheetName));

				if (this.pictureSheetGenerator != null) {
					this.pictureSheetGenerator.setImage(workbook, sheet);
				}

				if (this.sheetIndexSheetGenerator.getTemplateSheetName()
						.equals(templateSheetName)) {
					sheetIndexSheetNo = workbook.getNumberOfSheets()
							- originalSheetNum;

					String name = this.sheetIndexSheetGenerator
							.getSheetName();

					name = AbstractSheetGenerator.decideSheetName(name,
							sheetNameMap);

					monitor.subTaskWithCounter(name);

					workbook.setSheetName(workbook.getNumberOfSheets() - 1,
							name);
				} else {
					monitor.subTaskWithCounter(sheet.getSheetName());
				}

			} else {
				monitor.subTaskWithCounter("Removing template sheet");
				workbook.removeSheetAt(0);
			}

			monitor.worked(1);
		}

		originalSheetNum--;
	}

	if (sheetIndexSheetNo != -1) {
		this.sheetIndexSheetGenerator.generate(monitor, workbook,
				sheetIndexSheetNo, useLogicalNameAsSheetName,
				this.sheetNameMap, this.sheetObjectMap, diagram,
				loopDefinitionMap);
	}
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:72,代碼來源:ExportToExcelManager.java

示例11: readExcel2003

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static ArrayList<ArrayList<ArrayList<Object>>> readExcel2003(File file){
	try{
		ArrayList<ArrayList<ArrayList<Object>>> sheetArray = new ArrayList<ArrayList<ArrayList<Object>>> ();
		HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
		for(int sheetNum = 0;sheetNum < wb.getNumberOfSheets();sheetNum++){
			ArrayList<ArrayList<Object>> rowList = new ArrayList<ArrayList<Object>>();
			ArrayList<Object> colList;
			HSSFSheet sheet = wb.getSheetAt(sheetNum);
			HSSFRow row;
			HSSFCell cell;
			Object value;
			for(int i = 0 , rowCount = 0; rowCount < sheet.getPhysicalNumberOfRows() ; i++ ){
				row = sheet.getRow(i);
				colList = new ArrayList<Object>();
				if(row == null){
					//����ȡ��Ϊ��ʱ
					if(i != sheet.getPhysicalNumberOfRows()){//�ж��Ƿ������һ��
						rowList.add(colList);
					}
					continue;
				}else{
					rowCount++;
				}
				for( int j = 0 ; j <= row.getLastCellNum() ;j++){
					cell = row.getCell(j);
					if(cell == null ){
						//���õ�Ԫ��Ϊ��
						if(j != row.getLastCellNum()){//�ж��Ƿ��Ǹ��������һ����Ԫ��
							colList.add("");
						}
						continue;
					}
					switch(cell.getCellType()){
					 case XSSFCell.CELL_TYPE_STRING:  
		                    value = cell.getStringCellValue();  
		                    break;  
		                case XSSFCell.CELL_TYPE_NUMERIC:  
		                    if ("@".equals(cell.getCellStyle().getDataFormatString())) {  
		                        value = df.format(cell.getNumericCellValue());  
		                    } else if ("General".equals(cell.getCellStyle()  
		                            .getDataFormatString())) {  
		                        value = nf.format(cell.getNumericCellValue());  
		                    } else {  
		                        value = sdf.format(HSSFDateUtil.getJavaDate(cell  
		                                .getNumericCellValue()));  
		                    }  
		                    break;  
		                case XSSFCell.CELL_TYPE_BOOLEAN:  
		                    value = Boolean.valueOf(cell.getBooleanCellValue());
		                    break;  
		                case XSSFCell.CELL_TYPE_BLANK:  
		                    value = "";  
		                    break;  
		                default:  
		                    value = cell.toString();  
					}// end switch
					colList.add(value);
				}//end for j
				rowList.add(colList);
			}//end for i
			sheetArray.add(rowList);
		}// end sheetNum
		
		return sheetArray;
	}catch(Exception e){
		return null;
	}
}
 
開發者ID:sqyNick,項目名稱:JavaUtils,代碼行數:69,代碼來源:ExcelUtil.java


注:本文中的org.apache.poi.hssf.usermodel.HSSFWorkbook.getNumberOfSheets方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。