本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.close方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFWorkbook.close方法的具體用法?Java HSSFWorkbook.close怎麽用?Java HSSFWorkbook.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.close方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
List<PollOption> results = null;
try {
Long pollId = (Long) req.getSession().getAttribute("pollID");
results = DAOProvider.getDao().getPollOptions(pollId);
} catch (Exception ex) {
results = new ArrayList<>();
}
HSSFWorkbook workbook = DBUtility.getXLS(results);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition",
"attachment; filename=votingResults.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}
示例2: writeXLSFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void writeXLSFile() throws IOException {
HSSFWorkbook wbObj = new HSSFWorkbook();
HSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
HSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
HSSFCell cellObj = rowObj.createCell(col);
cellObj.setCellValue(rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例3: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String definitionFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-definicija.txt");
String resultFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-rezultati.txt");
List<Band> results = ServerUtilty
.getResults(definitionFile, resultFile);
HSSFWorkbook workbook = ServerUtilty.getXLS(results);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition",
"attachment; filename=votingResults.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}
示例4: exportTables
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void exportTables(List<String> tables, final String fileName) throws Exception {
workbook = new HSSFWorkbook();
for (int i = 0; i < tables.size(); i++) {
if (!tables.get(i).equals("android_metadata")) {
HSSFSheet sheet = workbook.createSheet(tables.get(i));
createSheet(tables.get(i), sheet);
}
}
File file = new File(mExportPath, fileName);
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
fos.flush();
fos.close();
workbook.close();
database.close();
}
示例5: 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();
}
示例6: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Integer a = null;
Integer b = null;
Integer n = null;
try {
a = Integer.valueOf(req.getParameter("a"));
b = Integer.valueOf(req.getParameter("b"));
n = Integer.valueOf(req.getParameter("n"));
} catch (Exception ex) {
req.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward(req,
resp);
return;
}
if (!isValid(a) || !isValid(b) || n < 1 || n > 5) {
req.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward(req,
resp);
return;
}
HSSFWorkbook workbook = getXLS(a, b, n);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition", "attachment; filename=powers.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}
示例7: getMsgListFromExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
@Override
public ArrayList<MsgEntity> getMsgListFromExcel(File targetFile) throws IOException {
ArrayList<MsgEntity> list = new ArrayList<MsgEntity>();
POIFSFileSystem fs = new POIFSFileSystem(targetFile);
HSSFWorkbook workBook = new HSSFWorkbook(fs);
try {
System.out.println("開始解析");
HSSFSheet sheet = workBook.getSheetAt(0);
int rows = sheet.getLastRowNum() + 1;
for (int r = 1; r < rows; r++) {
HSSFRow row = sheet.getRow(r);
if (row == null) {
continue;
}
MsgEntity msg = new MsgEntity();
String number = getStringVal(row.getCell(0));
if(StringUtils.isEmpty(number)){
continue;
}
msg.setTelNumber(number);
String templateId = getStringVal(row.getCell(1));
if (!StringUtils.isEmpty(templateId) && StringUtils.isNumeric(templateId)
&& templateId.indexOf(".") == -1) {
msg.setTemplateId(Long.parseLong(templateId));
}
msg.setContent(getStringVal(row.getCell(2)));
if (HSSFDateUtil.isCellDateFormatted(row.getCell(3))) {
msg.setSendTime(row.getCell(3).getDateCellValue());
}
list.add(msg);
}
} finally {
workBook.close();
}
return list;
}
示例8: createFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public void createFile(List<List<Creature>> listList, File file) {
StringReader reader = new StringReader();
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet1 = workbook.createSheet("Cycle1");
// Heading
HSSFRow heading = sheet1.createRow(0);
for(int j = 0; j < listList.size();j++){
List<Creature> list = new ArrayList<Creature>(listList.get(j));
heading.createCell(0+j*13).setCellValue("DNA");
heading.createCell(1+j*13).setCellValue("LifeExpectancy");
heading.createCell(2+j*13).setCellValue("Height");
heading.createCell(3+j*13).setCellValue("Width");
heading.createCell(4+j*13).setCellValue("Speed");
heading.createCell(5+j*13).setCellValue("Flight");
heading.createCell(6+j*13).setCellValue("OptTemperature");
heading.createCell(7+j*13).setCellValue("NumOffspring");
heading.createCell(8+j*13).setCellValue("PairChance");
heading.createCell(9+j*13).setCellValue("Carnivorous");
heading.createCell(10+j*13).setCellValue("#Environment");
List<String> uniqueDnaSequence = getAllDnaSequences(list);
for (int i = 0; i < uniqueDnaSequence.size(); i++) {
HSSFRow row = sheet1.getRow(i+1);
if(row == null){
row= sheet1.createRow(i+1);
}
int allelLength = properties.getAllelLength();
row.createCell(0+j*13).setCellValue(uniqueDnaSequence.get(i));
row.createCell(1+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 1, allelLength));
row.createCell(2+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 2, allelLength));
row.createCell(3+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 3, allelLength));
row.createCell(4+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 4, allelLength));
row.createCell(5+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 5, allelLength));
row.createCell(6+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 6, allelLength));
row.createCell(7+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 7, allelLength));
row.createCell(8+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 8, allelLength));
row.createCell(9+j*13).setCellValue(reader.readHexStringToInt(uniqueDnaSequence.get(i), 9, allelLength));
row.createCell(10+j*13).setCellValue(j);
}
sheet1.autoSizeColumn(0+j*11);
}
FileOutputStream out = new FileOutputStream(file);
workbook.write(out);
out.close();
workbook.close();
System.out.println("Files outputted to c:/EvolutionOutputs");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
示例9: outputResumeProcessResult
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void outputResumeProcessResult(Map<File, Resume> map, File outFile) throws IOException {
//工作簿
HSSFWorkbook excel = new HSSFWorkbook();
FileOutputStream fileoutputstream = new FileOutputStream(outFile);
try {
HSSFSheet sheet = excel.createSheet("簡曆處理結果");
// 寫表頭
HSSFRow headerRow = sheet.createRow(0);
for(int i = 0; i < HEADERS.length; i++) {
headerRow.createCell(i).setCellValue(HEADERS[i]);
}
// 寫內容
int rowNum = 1;
for(Map.Entry<File, Resume> entry : map.entrySet()) {
Resume resume = entry.getValue();
HSSFRow row = sheet.createRow(rowNum);
row.createCell(0).setCellValue(rowNum); // 序號
row.createCell(1).setCellValue(resume.getName()); // 姓名
row.createCell(2).setCellValue(resume.getJob()); // 應聘職位
row.createCell(3).setCellValue(resume.getSource()); // 簡曆來源
row.createCell(4).setCellValue(resume.getSchool()); // 畢業院校
row.createCell(5).setCellValue(resume.getEducation()); // 學曆
row.createCell(6).setCellValue(resume.getAge()); // 年齡
row.createCell(7).setCellValue(resume.getWorkDuration()); // 工作經驗
row.createCell(8).setCellValue(resume.getCompany()); // 現工作單位
row.createCell(9).setCellValue(resume.getPhone()); // 電話
row.createCell(10).setCellValue(resume.getMail()); // 郵箱
row.createCell(11).setCellValue(resume.getSex()); // 性別
row.createCell(12).setCellValue(resume.getBirthday()); // 生日
row.createCell(13).setCellValue(resume.getCity()); // 居住城市
row.createCell(14).setCellValue(resume.getAddress()); // 地址
rowNum++;
}
excel.write(fileoutputstream);
} finally {
fileoutputstream.close();
excel.close();
}
}