本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.getSheet方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFWorkbook.getSheet方法的具體用法?Java HSSFWorkbook.getSheet怎麽用?Java HSSFWorkbook.getSheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.getSheet方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadTemplateWorkbook
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private HSSFWorkbook loadTemplateWorkbook(InputStream template,
ERDiagram diagram) throws IOException {
HSSFWorkbook workbook = POIUtils.readExcelBook(template);
if (workbook == null) {
throw new IOException(
ResourceString.getResourceString("error.read.file"));
}
HSSFSheet wordsSheet = workbook.getSheet(WORDS_SHEET_NAME);
if (wordsSheet == null) {
throw new IOException(
ResourceString
.getResourceString("error.not.found.words.sheet"));
}
HSSFSheet loopsSheet = workbook.getSheet(LOOPS_SHEET_NAME);
if (loopsSheet == null) {
throw new IOException(
ResourceString
.getResourceString("error.not.found.loops.sheet"));
}
this.initLoopDefinitionMap(loopsSheet);
for (AbstractSheetGenerator sheetGenerator : SHHET_GENERATOR_LIST) {
sheetGenerator.init(wordsSheet);
}
this.sheetIndexSheetGenerator = new SheetIndexSheetGenerator();
this.sheetIndexSheetGenerator.init(wordsSheet);
return workbook;
}
示例2: workbookToData
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* workbook轉數據對象
* @param workbook excel表格對象
* @param rowNumber 開始行
* @return List
*/
public static JSONArray workbookToData(String propertiesPath,String key,String sheetName,HSSFWorkbook workbook,int rowNumber){
if (logger.isDebugEnabled()) {
logger.debug("workbookToData(String, String, String, HSSFWorkbook, int) - start"); //$NON-NLS-1$
}
JSONArray array = new JSONArray();
//將寫入excel的數據不能為空
if (workbook!=null) {
//讀取properties配置文件
PropertiesModel properties = PropertiesCacheUtil.loadProperties(propertiesPath);
if (properties!=null) {
//從properties中獲取導出對應的配置json
String columnJsonString = properties.get(key);
try {
//創建一個sheet
HSSFSheet sheet = null;
if (StringUtils.isNotBlank(sheetName)) {
sheet = workbook.getSheet(sheetName);
}
//如果未獲取到sheet則獲取第一個sheet
if (sheet==null) {
sheet = workbook.getSheetAt(0);
}
if (sheet!=null) {
//定義sheet的行碼,並保存列信息
//List<String> columnList = new ArrayList<String>();
JSONObject columnJson = JSONObject.parseObject(columnJsonString);
//讀取每列對應的列號通過標題
Map<Integer, String> map = readSheetHead(sheet, columnJson, rowNumber++);
//讀取內容
rowNumber = readSheetBody(sheet, map, rowNumber,array);
}else{
logger.error("workbookToData#sheet is null");
}
} catch (Exception e) {
logger.error("workbookToData#parse json error",e);
}
}else{
logger.warn("workbookToData#properties is null");
}
}
if (logger.isDebugEnabled()) {
logger.debug("workbookToData(String, String, String, HSSFWorkbook, int) - end"); //$NON-NLS-1$
}
return array;
}
示例3: loadTemplateWorkbook
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private HSSFWorkbook loadTemplateWorkbook(final InputStream template, final ERDiagram diagram) throws IOException {
final HSSFWorkbook workbook = POIUtils.readExcelBook(template);
if (workbook == null) {
throw new IOException(ResourceString.getResourceString("error.read.file"));
}
final HSSFSheet wordsSheet = workbook.getSheet(WORDS_SHEET_NAME);
if (wordsSheet == null) {
throw new IOException(ResourceString.getResourceString("error.not.found.words.sheet"));
}
final HSSFSheet loopsSheet = workbook.getSheet(LOOPS_SHEET_NAME);
if (loopsSheet == null) {
throw new IOException(ResourceString.getResourceString("error.not.found.loops.sheet"));
}
initLoopDefinitionMap(loopsSheet);
for (final AbstractSheetGenerator sheetGenerator : SHHET_GENERATOR_LIST) {
sheetGenerator.init(wordsSheet);
}
sheetIndexSheetGenerator = new SheetIndexSheetGenerator();
sheetIndexSheetGenerator.init(wordsSheet);
return workbook;
}