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


Java XSSFWorkbook.write方法代碼示例

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


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

示例1: writeXLSX

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
/**
 * Writes the example set into a excel file with XLSX format. If you want to write it in XLS
 * format use {@link #write(ExampleSet, Charset, OutputStream)}.
 *
 * @param exampleSet
 *            the exampleSet to write
 * @param sheetName
 *            name of the excel sheet which will be created.
 * @param dateFormat
 *            a string which describes the format used for dates.
 * @param numberFormat
 *            a string which describes the format used for numbers.
 * @param outputStream
 *            the stream to write the file to
 * @param opProg
 *            increases the progress by the number of examples to provide a more detailed
 *            progress.
 */
public static void writeXLSX(ExampleSet exampleSet, String sheetName, String dateFormat, String numberFormat,
		OutputStream outputStream, OperatorProgress opProg) throws WriteException, IOException,
		ProcessStoppedException {
	// .xlsx files can only store up to 16384 columns, so throw error in case of more
	if (exampleSet.getAttributes().allSize() > 16384) {
		throw new IllegalArgumentException(I18N.getMessage(I18N.getErrorBundle(),
				"export.excel.excel_xlsx_file_exceeds_column_limit"));
	}

	try {
		XSSFWorkbook workbook = new XSSFWorkbook();

		Sheet sheet = workbook.createSheet(WorkbookUtil.createSafeSheetName(sheetName));
		dateFormat = dateFormat == null ? DEFAULT_DATE_FORMAT : dateFormat;

		numberFormat = numberFormat == null ? "#.0" : numberFormat;

		writeXLSXDataSheet(workbook, sheet, dateFormat, numberFormat, exampleSet, opProg);
		workbook.write(outputStream);
	} finally {
		outputStream.flush();
		outputStream.close();
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:43,代碼來源:ExcelExampleSetWriter.java

示例2: writeXLSXFile

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static void writeXLSXFile() throws IOException {

			// @SuppressWarnings("resource")
			XSSFWorkbook wbObj = new XSSFWorkbook();
			XSSFSheet sheet = wbObj.createSheet(sheetName);
			for (int row = 0; row < tableData.size(); row++) {
				XSSFRow rowObj = sheet.createRow(row);
				rowData = tableData.get(row);
				for (int col = 0; col < rowData.size(); col++) {
					XSSFCell cell = rowObj.createCell(col);
					cell.setCellValue(rowData.get(col));
					logger.info("Writing " + row + " " + col + "  " + rowData.get(col));
				}
			}
			FileOutputStream fileOut = new FileOutputStream(excelFileName);
			wbObj.write(fileOut);
			wbObj.close();
			fileOut.flush();
			fileOut.close();
		}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:21,代碼來源:TableEditorEx.java

示例3: streamSpreadsheet

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void streamSpreadsheet(OutputStream outputStream,
                              Spreadsheet spreadsheet) throws IOException {
    final XSSFWorkbook workbook = xsffWorkbokFactory.createInstance();
    final XSSFSheet sheet = workbook.createSheet("Export");
    final Map<String, CellStyle> styles = new HashMap<>();

    createStyles(styles, workbook);
    setColumnSizes(sheet, spreadsheet.getSpreadsheetHeader());

    createHeader(styles, sheet, spreadsheet.getSpreadsheetHeader());

    int rowNumber = 1;
    for (List<Object> row : spreadsheet.getSpreadsheetRows()) {
        final Row excelRow = sheet.createRow(rowNumber);
        int columnNumber = 0;
        for (Object column : row) {
            final Cell cell = excelRow.createCell(columnNumber);

            if (column != null) {
                if (column instanceof Integer) {
                    cell.setCellValue((int) column);
                } else if (column instanceof Long) {
                    cell.setCellValue((long) column);
                } else if (column instanceof Double || column instanceof Float) {
                    cell.setCellValue((double) column);
                } else if (column instanceof Date) {
                    cell.setCellStyle(styles.get("date"));
                    cell.setCellValue((Date) column);
                } else {
                    cell.setCellStyle(styles.get("wrap"));
                    cell.setCellValue(column.toString());
                }

            }
            columnNumber++;
        }

        rowNumber++;
    }

    workbook.write(outputStream);
}
 
開發者ID:Dactilo,項目名稱:spring-spreadsheet,代碼行數:44,代碼來源:ExcelStreamer.java

示例4: readExcel

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public String readExcel(String date) {
    HashMap<String, String> map = new HashMap<String, String>();
    initResidualMaps(date, map);
    try {
        File xlsxFile = getFile();
        XSSFWorkbook workbook = processXlsx(xlsxFile, map);
        File file = new File(FILE + date + ".xlsx");
        FileOutputStream fout = new FileOutputStream(file);
        workbook.write(fout);
        return FILE + date + ".xlsx";
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:16,代碼來源:ResidualDownload.java

示例5: exportSpreadsheet

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public static <T> void exportSpreadsheet(OutputStream target, Collection<T> data, String[] header, Function<T, Object>... getters) throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    addSheet(null, workbook, data, header, getters);
    workbook.write(target);
}
 
開發者ID:Adobe-Consulting-Services,項目名稱:aem-epic-tool,代碼行數:6,代碼來源:ReportUtil.java

示例6: Document

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public Document(List<RESTResource> resourceList) {
	String fileName = "API Document.xlsx";
	wb = new XSSFWorkbook();
	XSSFSheet sheet = wb.createSheet("API");
	
	XSSFRow rowHead = sheet.createRow(0);
	rowHead.createCell(0).setCellValue("Function Category");
	rowHead.createCell(1).setCellValue("Summary");
	rowHead.createCell(2).setCellValue("Method");
	rowHead.createCell(3).setCellValue("URI");
	rowHead.createCell(4).setCellValue("Request Header");
	rowHead.createCell(5).setCellValue("Params");
	rowHead.createCell(6).setCellValue("Request Body");
	rowHead.createCell(7).setCellValue("Success Code");
	rowHead.createCell(8).setCellValue("Response Header");
	rowHead.createCell(9).setCellValue("Response Body");
	rowHead.createCell(10).setCellValue("Failure Code");
	rowHead.createCell(11).setCellValue("ETC");
	
	int rowCount = 1;
	
	for(RESTResource resource : resourceList) {
		XSSFRow row = sheet.createRow(rowCount++);
		
		row.createCell(0).setCellValue(resource.getFunctionCategory());
		row.createCell(1).setCellValue(resource.getSummary());
		row.createCell(2).setCellValue(resource.getMethod());
		row.createCell(3).setCellValue(resource.getUri());
		row.createCell(4).setCellValue(getKeyValueStr(resource.getRequestHeaders()));
		row.createCell(5).setCellValue(getKeyValueStr(resource.getParams()));
		row.createCell(6).setCellValue(getKeyValueStr(resource.getRequestBody()));
		row.createCell(7).setCellValue(resource.getSuccessCode());
		row.createCell(8).setCellValue(getKeyValueStr(resource.getResponseHeaders()));
		row.createCell(9).setCellValue(getKeyValueStr(resource.getResponseBody()));
		row.createCell(10).setCellValue(resource.getFailureCode());
		row.createCell(11).setCellValue(resource.getEtc());
	}
	
	try {
		wb.write(new FileOutputStream(fileName));
		Log.info("REST Resource Documentation Complete");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:JoMingyu,項目名稱:Bobsim-Server,代碼行數:46,代碼來源:Document.java

示例7: Document

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public Document(List<RESTResource> resourceList) {
	String fileName = "API Document.xlsx";
	wb = new XSSFWorkbook();
	XSSFSheet sheet = wb.createSheet("API");
	
	XSSFRow rowHead = sheet.createRow(0);
	rowHead.createCell(0).setCellValue("Function Category");
	rowHead.createCell(1).setCellValue("Summary");
	rowHead.createCell(2).setCellValue("Method");
	rowHead.createCell(3).setCellValue("URI");
	rowHead.createCell(4).setCellValue("Request Header");
	rowHead.createCell(5).setCellValue("Params");
	rowHead.createCell(6).setCellValue("Request Body");
	rowHead.createCell(7).setCellValue("Success Code");
	rowHead.createCell(8).setCellValue("Response Header");
	rowHead.createCell(9).setCellValue("Response Body");
	rowHead.createCell(10).setCellValue("Failure Code");
	rowHead.createCell(11).setCellValue("ETC");
	
	int rowCount = 1;
	
	for(RESTResource resource : resourceList) {
		XSSFRow row = sheet.createRow(rowCount++);
		
		row.createCell(0).setCellValue(resource.getFunctionCategory());
		row.createCell(1).setCellValue(resource.getSummary());
		row.createCell(2).setCellValue(resource.getMethod());
		row.createCell(3).setCellValue(resource.getUri());
		row.createCell(4).setCellValue(getKeyValueStr(resource.getRequestHeaders()));
		row.createCell(5).setCellValue(getKeyValueStr(resource.getRequestParams()));
		row.createCell(6).setCellValue(getKeyValueStr(resource.getRequestBody()));
		row.createCell(7).setCellValue(resource.getSuccessCode());
		row.createCell(8).setCellValue(getKeyValueStr(resource.getResponseHeaders()));
		row.createCell(9).setCellValue(getKeyValueStr(resource.getResponseBody()));
		row.createCell(10).setCellValue(resource.getFailureCode());
		row.createCell(11).setCellValue(resource.getEtc());
	}
	
	try {
		wb.write(new FileOutputStream(fileName));
		Log.info("REST Resource Documentation Complete");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:JoMingyu,項目名稱:Server-Quickstart-Vert.x,代碼行數:46,代碼來源:Document.java

示例8: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {
		DataBase database = DataBase.getInstance();
		SafeResultSet resultSet;
		SafeResultSet extensionStateResultSet;

		File file = getFile();

		try {
			wb = new XSSFWorkbook(new FileInputStream(file));

			XSSFSheet sheet = wb.getSheetAt(0);

			for (Row row : sheet) {
				for (Cell cell : row) {
					switch (cell.getCellType()) {
						case Cell.CELL_TYPE_NUMERIC:
							StringBuilder sb = new StringBuilder(Double.toString(cell.getNumericCellValue()));

							String studentNumber = AES256.encrypt(sb.toString().substring(0, 4));
							int classId = 0;

							resultSet = database.executeQuery("SELECT * FROM student_data WHERE number='", studentNumber, "'");

							if (resultSet.next()) {
								String uid = resultSet.getString("uid");
								extensionStateResultSet = database.executeQuery("SELECT * FROM extension_apply WHERE uid='", uid, "'");
								if (extensionStateResultSet.next()) {
									classId = extensionStateResultSet.getInt("class");
								}
							}

							XSSFRow studentRow = sheet.getRow(cell.getRowIndex());
							XSSFCell extensionStateCell = studentRow.getCell(cell.getColumnIndex() + 2);
							extensionStateCell.setCellValue(CLASS_NAMES[classId]);

							break;
					}
				}
			}

			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "연장신청.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();

			String fileName = new String("연장신청.xlsx".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "연장신청.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}else{
		context.response().setStatusCode(400).end();
		context.response().end("You are not admin!");
		context.response().close();
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:62,代碼來源:ExtensionDownloadRouter.java

示例9: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {

		DataBase database = DataBase.getInstance();
		SafeResultSet resultSet;
		SafeResultSet stayStateResultSet;
		SafeResultSet stayDefaultResultSet;

		File file = getFile();

		try {
			wb = new XSSFWorkbook(new FileInputStream(file));

			XSSFSheet sheet = wb.getSheetAt(0);

			for (Row row : sheet) {
				for (Cell cell : row) {
					switch (cell.getCellType()) {
						case Cell.CELL_TYPE_NUMERIC:
							StringBuilder sb = new StringBuilder(Double.toString(cell.getNumericCellValue()));

							String studentNumber = AES256.encrypt(sb.toString().substring(0, 4));

							resultSet = database.executeQuery("SELECT * FROM student_data WHERE number='", studentNumber, "'");

							if (resultSet.next()) {
								String uid = resultSet.getString("uid");
								stayStateResultSet = database.executeQuery("SELECT * FROM stay_apply WHERE uid='", uid, "'");

								if (stayStateResultSet.next()) {
									// 잔류신청을 한 경우
									setCellValues(stayStateResultSet, database, sheet, cell, uid);
								} else {
									// 잔류신청 정보 없음
									stayDefaultResultSet = database.executeQuery("SELECT * FROM stay_apply_default WHERE uid='", uid, "'");
									// default 값 조회
									if (stayDefaultResultSet.next()) {
										setCellValues(stayDefaultResultSet, database, sheet, cell, uid);
									}
								}
							}
							break;
					}
				}
			}

			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "외출신청.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();

			String fileName = new String("외출신청.xlsx".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "외출신청.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			e.printStackTrace();
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}else{
		context.response().setStatusCode(400);
		context.response().end("You are Not Admin");
		context.response().close();
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:68,代碼來源:GoingoutDownloadRouter.java

示例10: handle

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext context) {
	if(AdminManager.isAdmin(context)) {
		DataBase database = DataBase.getInstance();
		SafeResultSet reportFacilityResultSet;
		
		File file = getFile();
		
		try {
			wb = new XSSFWorkbook(new FileInputStream(file));
			
			XSSFSheet sheet = wb.getSheetAt(0);
			int rowCount = 0;
			XSSFRow titleRow = sheet.createRow(rowCount++);
			titleRow.createCell(0).setCellValue("호실");
			titleRow.createCell(1).setCellValue("작성자");
			titleRow.createCell(2).setCellValue("제목");
			titleRow.createCell(3).setCellValue("신고 내용");
			titleRow.createCell(4).setCellValue("신고 날짜");
			
			reportFacilityResultSet = database.executeQuery("SELECT * FROM facility_report");
			while(reportFacilityResultSet.next()) {
				XSSFRow row = sheet.createRow(rowCount++);
				row.createCell(0).setCellValue(reportFacilityResultSet.getString("room") + "호");
				row.createCell(1).setCellValue(reportFacilityResultSet.getString("writer"));
				row.createCell(2).setCellValue(reportFacilityResultSet.getString("title"));
				row.createCell(3).setCellValue(reportFacilityResultSet.getString("content"));
				row.createCell(4).setCellValue(reportFacilityResultSet.getString("write_date").split(" ")[0]);
			}
			
			FileOutputStream xlsToSave = new FileOutputStream(FILE_DIR + "시설고장신고.xlsx");
			wb.write(xlsToSave);
			xlsToSave.close();
			
			String fileName = new String("시설고장신고.xls".getBytes("UTF-8"), "ISO-8859-1");
			context.response()
				.putHeader(HttpHeaders.CONTENT_DISPOSITION, "filename=" + fileName)
				.sendFile(FILE_DIR + "시설고장신고.xlsx");
			context.response().close();
		} catch (IOException | SQLException e) {
			context.response().setStatusCode(500).end();
			context.response().close();
		}
	}
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:46,代碼來源:ReportDownloadRouter.java

示例11: Document

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public Document(List<RESTResource> resourceList) {
	String fileName = "API Document.xlsx";
	wb = new XSSFWorkbook();
       XSSFSheet sheet = wb.createSheet("API");
	
	XSSFRow rowHead = sheet.createRow(0);
	rowHead.createCell(0).setCellValue("Function Category");
	rowHead.createCell(1).setCellValue("Summary");
	rowHead.createCell(2).setCellValue("Method");
	rowHead.createCell(3).setCellValue("URI");
	rowHead.createCell(4).setCellValue("Request Header");
	rowHead.createCell(5).setCellValue("Params");
	rowHead.createCell(6).setCellValue("Request Body");
	rowHead.createCell(7).setCellValue("Success Code");
	rowHead.createCell(8).setCellValue("Response Header");
	rowHead.createCell(9).setCellValue("Response Body");
	rowHead.createCell(10).setCellValue("Failure Code");
	rowHead.createCell(11).setCellValue("ETC");
	
	int rowCount = 1;
	
	for(RESTResource resource : resourceList) {
		XSSFRow row = sheet.createRow(rowCount++);
		
		row.createCell(0).setCellValue(resource.getFunctionCategory());
		row.createCell(1).setCellValue(resource.getSummary());
		row.createCell(2).setCellValue(resource.getMethod());
		row.createCell(3).setCellValue(resource.getUri());
		row.createCell(4).setCellValue(getKeyValueStr(resource.getRequestHeaders()));
		row.createCell(5).setCellValue(getKeyValueStr(resource.getParams()));
		row.createCell(6).setCellValue(getKeyValueStr(resource.getRequestBody()));
		row.createCell(7).setCellValue(resource.getSuccessCode());
		row.createCell(8).setCellValue(getKeyValueStr(resource.getResponseHeaders()));
		row.createCell(9).setCellValue(getKeyValueStr(resource.getResponseBody()));
		row.createCell(10).setCellValue(resource.getFailureCode());
		row.createCell(11).setCellValue(resource.getEtc());
	}
	
	try {
		wb.write(new FileOutputStream(fileName));
		Log.info("REST Resource Documentation Complete");
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:JoMingyu,項目名稱:Daejeon-People,代碼行數:46,代碼來源:Document.java

示例12: exportExcelXLSX

import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
public void exportExcelXLSX(String saveOption){
	//run standard checks before exporting
	if (!exportChecks(saveOption)) return;

	JFileChooser jfc = new JFileChooser(System.getProperty("user.home"));
	ExcelFileFilter eff = new ExcelFileFilter();
	jfc.setFileFilter(eff);
	String defaultName = desc.name.replace(":", "") + ".xlsx";

	if(defaultName.contains("Data Table ")){
		defaultName = defaultName.replace("Data Table ", "");
	}

	File f=new File(defaultName);
	jfc.setSelectedFile(f);
	do {
		int c = jfc.showSaveDialog(null);
		if (c==JFileChooser.CANCEL_OPTION||c==JFileChooser.ERROR_OPTION) return;
		f = jfc.getSelectedFile();
		if (f.exists()) {
			c=JOptionPane.showConfirmDialog(null, "File Already Exists\nConfirm Overwrite");
			if (c==JOptionPane.OK_OPTION)break;
			if (c==JOptionPane.CANCEL_OPTION) return;
		}
	} while (f.exists());

	try {
		if (!f.getName().endsWith(".xlsx")){
			System.out.println(f.getName());
			JOptionPane.showMessageDialog(null, "Save did not complete. Must end in .xlsx. Try again.");
		}else{
			XSSFWorkbook xlsxWB = new XSSFWorkbook();
			CreationHelper createHelper = xlsxWB.getCreationHelper();
			XSSFSheet xlsxSheet1 = xlsxWB.createSheet("First Sheet");
			Row row = null;
			
			int[] ind;
			if (saveOption.equals("selection")) {
				ind = dataT.getSelectedRows();
			} else if (saveOption.equals("plottable")) {
				ind = getPlottableRows();
			} else {
				ind = new int[dataT.getRowCount()];
				for (int i=0; i<dataT.getRowCount(); i++) ind[i] = i;
			}
			int xlsxCol = dataT.getColumnCount();
			row = xlsxSheet1.createRow((0));
			//don't include Plot column
			for (int c=1; c<xlsxCol; c++){
				String columnName = dataT.getColumnName(c);
				row.createCell(c-1).setCellValue(columnName);
			}

			for (int r=1; r<=ind.length; r++){
				row = xlsxSheet1.createRow((r));
				for (int c=1; c<xlsxCol; c++){
					Object o = dataT.getValueAt(ind[r-1], c);
					String input1 = null;
					if(o instanceof String && ((String)o).equals("NaN")){
						o = "";
						input1 = o.toString();
						row.createCell(c-1).setCellValue(input1);
					}else if(o instanceof String){
						row.createCell(c-1).setCellValue((String)o);
					}
				}
			}
			FileOutputStream xlsxOut = new FileOutputStream(f);
			xlsxWB.write(xlsxOut);
			xlsxOut.close();
		}
	} catch (Exception ex){
		ex.printStackTrace();
	}
}
 
開發者ID:iedadata,項目名稱:geomapapp,代碼行數:76,代碼來源:UnknownDataSet.java


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