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


Java HSSFWorkbook.write方法代碼示例

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


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

示例1: test

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
@Test
public void test() throws IOException {
    HSSFWorkbook workbook = createWorkbook();

    byte[] buffer;
    try (ByteArrayOutputStream stream = new ByteArrayOutputStream(1024)) {
        workbook.write(stream);
        stream.flush();
        buffer = stream.toByteArray();
    }

    Map<String, BoundaryPoint> boundaryPoints;
    try (InputStream stream = new ByteArrayInputStream(buffer)) {
        BoundaryPointXlsParser parser = new BoundaryPointXlsParser();
        boundaryPoints = parser.parse(stream);
    }

    assertEquals(1, boundaryPoints.size());
    BoundaryPoint point = boundaryPoints.get("BoundaryPoint FR-BE");
    assertNotNull(point);
    assertEquals("BoundaryPoint FR-BE", point.getName());
    assertEquals(Country.FR, point.getBorderFrom());
    assertEquals(Country.BE, point.getBorderTo());
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:25,代碼來源:BoundaryPointXlsParserTest.java

示例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();
		}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:21,代碼來源:TableEditorEx.java

示例3: 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();
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:23,代碼來源:GlasanjeXLSServlet.java

示例4: 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();
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:23,代碼來源:GlasanjeXLSServlet.java

示例5: 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();
}
 
開發者ID:androidmads,項目名稱:SQLite2XL,代碼行數:17,代碼來源:SQLiteToExcel.java

示例6: createExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/** エクセル出力 */
@Execute(validator = false)
public String createExcel(){
	
	ExcelDto dto = new ExcelDto();
	dto.setMeetingName(partyDto.meetingName);
	dto.setMemberList(partyDto.tMemberOn);
	
	HSSFWorkbook wb = excelFpao.excelTemplate(dto);
	
	httpServletResponse.setHeader(
			"Content-Disposition",
			"attachment; filename=" + partyDto.meetingName + System.currentTimeMillis() + ".xls");
	
	try {
		OutputStream out = httpServletResponse.getOutputStream();
		wb.write(out);
	        out.close();		
	} catch (IOException e) {} 	
	
return null;	
}
 
開發者ID:kagucho,項目名稱:tsubonesystem2,代碼行數:23,代碼來源:PartyAttendListAction.java

示例7: createExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/** エクセル出力 */
@Execute(validator = false)
public String createExcel(){
	
	ExcelDto dto = new ExcelDto();	
	dto.setMeetingName(partyDto.meetingName);
	dto.setMemberList(partyDto.tMemberOn);
	
	HSSFWorkbook wb = excelFpao.excelTemplate(dto);
	
	httpServletResponse.setHeader(
			"Content-Disposition",
			"attachment; filename=" + partyDto.meetingName + System.currentTimeMillis() + ".xls");
	
	try {
		OutputStream out = httpServletResponse.getOutputStream();
		wb.write(out);
	        out.close();		
	} catch (IOException e) {} 	
	
return null;	
}
 
開發者ID:kagucho,項目名稱:tsubonesystem2,代碼行數:23,代碼來源:PartyAttendListAction.java

示例8: createExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
 * 創建文件
 * @param response
 * @param workbook
 * @param fileName
 * @return boolean
 * @throws Exception
 */
public static boolean createExcel(HttpServletResponse response,
		HSSFWorkbook workbook, String fileName) throws Exception {
	boolean flag = false;
	try {
		response.reset();
		response.setHeader("Content-Disposition", "attachment;filename="
				+ new String(fileName.getBytes(), "iso8859-1"));

		ServletOutputStream out = response.getOutputStream();
		workbook.write(out);
		// 彈出下載對話框
		out.flush();
		out.close();
		flag = true;
	} catch (Exception e) {
		logger.error(fileName + " :文件創建失敗");
		throw e;
	}
	return flag;
}
 
開發者ID:wufeisoft,項目名稱:data,代碼行數:29,代碼來源:CreateExcelUtil.java

示例9: writeExcelFile

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void writeExcelFile(File excelFile, HSSFWorkbook workbook)
		throws Exception {
	FileOutputStream fos = null;
	BufferedOutputStream bos = null;

	try {
		fos = new FileOutputStream(excelFile);
		bos = new BufferedOutputStream(fos);
		workbook.write(bos);

	} catch (FileNotFoundException e) {
		throw new InputException(e);

	} finally {
		if (bos != null) {
			bos.close();
		}
		if (fos != null) {
			fos.close();
		}
	}
}
 
開發者ID:kozake,項目名稱:ermaster-k,代碼行數:23,代碼來源:POIUtils.java

示例10: write

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public void write(String src) throws IOException{
  
  System.out.println(src);
  HSSFWorkbook wb = new HSSFWorkbook();
  HSSFSheet sheet = wb.createSheet("Resultats");
  
  for (int i=0; i<size(); i++) {
    HSSFRow row = sheet.createRow(i);
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(get(i).area());
  }
  
  
  FileOutputStream fileOut;
    fileOut = new FileOutputStream(src);
    wb.write(fileOut);
    fileOut.close();
}
 
開發者ID:IGNF,項目名稱:geoxygene,代碼行數:19,代碼來源:VectPolygon.java

示例11: createExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
private void createExcel(OutputStream out, IDocument doc, WebInput wi)
		throws IOException, ServletException {
	this.setContentType("application/vnd.ms-excel");
	HSSFWorkbook wb = new HSSFWorkbook();
	DocInfo di = new DocInfo(IDocument.TYPE_MS_EXCEL);
	try {
		di.setExcelDocument(wb);
		doc.createContent(wi, di);
		wb.write(out);
	} catch (Exception e) {
		throw new ServletException(e);
	} finally {
		if (out != null) {
			out.flush();
			out.close();
			out = null;
		}
		di = null;
		doc = null;
		wb = null;
	}
}
 
開發者ID:jbeetle,項目名稱:BJAF3.x,代碼行數:23,代碼來源:DocumentController.java

示例12: writeExcelFile

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
public static void writeExcelFile(final File excelFile, final HSSFWorkbook workbook) throws Exception {
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;

    try {
        fos = new FileOutputStream(excelFile);
        bos = new BufferedOutputStream(fos);
        workbook.write(bos);

    } catch (final FileNotFoundException e) {
        throw new InputException(e);

    } finally {
        if (bos != null) {
            bos.close();
        }
        if (fos != null) {
            fos.close();
        }
    }
}
 
開發者ID:roundrop,項目名稱:ermasterr,代碼行數:22,代碼來源:POIUtils.java

示例13: createExcel

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
/**
 * 創建文件
 * @param response
 * @param workbook
 * @param fileName
 * @return boolean
 * @throws Exception
 */
public static  FileTransfer createExcel(HttpServletResponse response,
		HSSFWorkbook workbook, String fileName) throws Exception {
	boolean flag = false;
	try {
		response.reset();
		response.setHeader("Content-Disposition", "attachment;filename="
				+ new String(fileName.getBytes(), "iso8859-1"));

		//ServletOutputStream out = response.getOutputStream();
		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		workbook.write(buffer);
		return new FileTransfer(fileName, "application/vnd.ms-excel", buffer.toByteArray());
		// 彈出下載對話框
		//out.flush();
		//out.close();
		//flag = true;
	} catch (Exception e) {
		logger.error(fileName + " :文件創建失敗");
		throw e;
	}
	//return flag;
}
 
開發者ID:wufeisoft,項目名稱:ryf_mms2,代碼行數:31,代碼來源:CreateExcelUtil.java

示例14: exportInnertion

import org.apache.poi.hssf.usermodel.HSSFWorkbook; //導入方法依賴的package包/類
@Override
   public void exportInnertion(OutputStream servletOut, List header,
		List data) throws IOException {
	if (header == null || header.isEmpty()) {
		return;
	}
	HSSFWorkbook workbook = ExcelUtil.export(header, data);
	workbook.write(servletOut);

}
 
開發者ID:fellyvon,項目名稱:wasexport,代碼行數:11,代碼來源:ExcelExport.java

示例15: 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();
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:33,代碼來源:PowersServlet.java


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