本文整理汇总了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;
}