本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFSheet.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFSheet.iterator方法的具體用法?Java HSSFSheet.iterator怎麽用?Java HSSFSheet.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFSheet
的用法示例。
在下文中一共展示了HSSFSheet.iterator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
public Map<String, BoundaryPoint> parse(InputStream is) throws IOException {
Map<String, BoundaryPoint> boundaryPoints = new HashMap<>();
HSSFWorkbook workbook = new HSSFWorkbook(is);
HSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIterator = sheet.iterator();
rowIterator.next();
rowIterator.next();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Cell boundaryPointNameCell = row.getCell(13);
Cell borderFromCell = row.getCell(14);
Cell borderToCell = row.getCell(15);
String boundaryPointName = boundaryPointNameCell.getStringCellValue();
if (boundaryPointName.equals("-")) {
continue;
}
Country borderFrom = toCountry(borderFromCell.getStringCellValue());
Country borderTo = toCountry(borderToCell.getStringCellValue());
boundaryPoints.put(boundaryPointName, new BoundaryPoint(boundaryPointName, borderFrom, borderTo));
}
return boundaryPoints;
}
示例2: convert
import org.apache.poi.hssf.usermodel.HSSFSheet; //導入方法依賴的package包/類
@Override
public ByteArrayOutputStream convert(InputStream stream) {
ByteArrayOutputStream outStream;
try {
outStream = new ByteArrayOutputStream();
// Read workbook into HSSFWorkbook
HSSFWorkbook my_xls_workbook = new HSSFWorkbook(stream);
// Read worksheet into HSSFSheet
HSSFSheet my_worksheet = my_xls_workbook.getSheetAt(0);
// To iterate over the rows
Iterator<Row> rowIterator = my_worksheet.iterator();
// We will create output PDF document objects at this point
Document pdf = new Document();
PdfWriter.getInstance(pdf, outStream);
pdf.open();
// we have two columns in the Excel sheet, so we create a PDF table
// with two columns
// Note: There are ways to make this dynamic in nature, if you want
// to.
PdfPTable my_table = new PdfPTable(2);
// We will use the object below to dynamically add new data to the
// table
PdfPCell table_cell;
// Loop through rows.
printPdf(rowIterator, my_table);
// Finally add the table to PDF document
pdf.add(my_table);
pdf.close();
// we created our pdf file..
stream.close(); // close xls
return outStream;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}