本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFWorkbook.createSheet方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFWorkbook.createSheet方法的具體用法?Java XSSFWorkbook.createSheet怎麽用?Java XSSFWorkbook.createSheet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFWorkbook
的用法示例。
在下文中一共展示了XSSFWorkbook.createSheet方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
}
}
示例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();
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: 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();
}
}
示例6: 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);
}
示例7: 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();
}
}
示例8: createBreedingSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
static void createBreedingSheet(List<RaceResult> raceResults, XSSFWorkbook workbook) {
// Breeding
XSSFSheet sheet = workbook.createSheet("Breeding");
int row = 0;
int col = 0;
createBreedingHeaderRow(sheet, row++, col);
for (int i = 0; i < raceResults.size(); i++) {
RaceResult raceResult = raceResults.get(i);
validate(raceResult);
List<Starter> winners = raceResult.getWinners();
if (winners != null) {
for (Starter winner : winners) {
int winnersColNum = 0;
XSSFRow winnerRow = sheet.createRow(row++);
RaceDistance raceDistance =
raceResult.getDistanceSurfaceTrackRecord().getRaceDistance();
winnersColNum = fillStandardCols(raceResult, winner, winnersColNum,
winnerRow, raceDistance);
// sex
asText(winnerRow, winnersColNum++, winner.getHorse().getSex());
// sire
asText(winnerRow, winnersColNum++, winner.getHorse().getSire().getName());
// dam
asText(winnerRow, winnersColNum++, winner.getHorse().getDam().getName());
// damSire
asText(winnerRow, winnersColNum++, winner.getHorse().getDamSire().getName());
// foalDate
asDate(winnerRow, winnersColNum++, winner.getHorse().getFoalingDate())
.setCellStyle(dateFormat);
// age
asNumber(winnerRow, winnersColNum++,
(winner.getHorse().getFoalingDate() != null ?
Period.between(winner.getHorse().getFoalingDate(),
raceResult.getRaceDate()).getYears() : null));
}
}
}
}
示例9: createWageringSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook; //導入方法依賴的package包/類
static void createWageringSheet(List<RaceResult> raceResults, XSSFWorkbook workbook) {
// Breeding
XSSFSheet sheet = workbook.createSheet("Wagering");
int row = 0;
int col = 0;
createWageringHeaderRow(sheet, row++, col);
for (int i = 0; i < raceResults.size(); i++) {
RaceResult raceResult = raceResults.get(i);
validate(raceResult);
int raceColNum = 0;
XSSFRow raceRow = sheet.createRow(row++);
RaceDistance raceDistance =
raceResult.getDistanceSurfaceTrackRecord().getRaceDistance();
raceColNum = fillSeedCols(raceResult, raceColNum, raceRow, raceDistance);
// List<String> columns = Arrays.asList("totalWpsPool", "winPayoff", "placePayoff",
// "showPayoff", "doublePayoff", "doublePool", "exactaPayoff", "exactaPool",
// "trifectaPayoff", "trifectaPool", "superfectaPayoff", "superfectaPool",
// "pick3Payoff", "pick3Pool", "pick4Payoff", "pick4Pool", "pick5Payoff",
// "pick5Pool");
WagerPayoffPools wagerPayoffPools = raceResult.getWagerPayoffPools();
WagerPayoffPools.WinPlaceShowPayoffPool wpsPayoffPools =
wagerPayoffPools.getWinPlaceShowPayoffPools();
List<WagerPayoffPools.ExoticPayoffPool> exoticPayoffPools =
wagerPayoffPools.getExoticPayoffPools();
Starter winner = raceResult.getWinners().get(0);
// winPayoff
asNumber(raceRow, raceColNum++,
(winner.getWinPlaceShowPayoff() != null &&
winner.getWinPlaceShowPayoff().getWin() != null ?
winner.getWinPlaceShowPayoff().getWin().getPayoff() : null))
.setCellStyle(twoDigitCommaFormat);
// placePayoff
asNumber(raceRow, raceColNum++,
(winner.getWinPlaceShowPayoff() != null &&
winner.getWinPlaceShowPayoff().getPlace() != null ?
winner.getWinPlaceShowPayoff().getPlace().getPayoff() : null))
.setCellStyle(twoDigitCommaFormat);
// showPayoff
asNumber(raceRow, raceColNum++,
(winner.getWinPlaceShowPayoff() != null &&
winner.getWinPlaceShowPayoff().getShow() != null ?
winner.getWinPlaceShowPayoff().getShow().getPayoff() : null))
.setCellStyle(twoDigitCommaFormat);
// totalWpsPool
asNumber(raceRow, raceColNum++, wpsPayoffPools.getTotalWinPlaceShowPool())
.setCellStyle(commaNumberFormat);
List<String> horizontals = Arrays.asList("Daily Double", "Exacta", "Trifecta",
"Superfecta", "Pick 3", "Pick 4", "Pick 5");
for (String horizontal : horizontals) {
Optional<WagerPayoffPools.ExoticPayoffPool> wager = exoticPayoffPools.stream()
.filter(exoticPayoffPool -> exoticPayoffPool.getName()
.equalsIgnoreCase(horizontal)).findFirst();
// payoff
asNumber(raceRow, raceColNum++,
(wager.isPresent() && wager.get().getPayoff() != null ?
((double) wager.get().getPayoff() / wager.get().getUnit()) * 2 :
null))
.setCellStyle(twoDigitCommaFormat);
// pool
asNumber(raceRow, raceColNum++,
(wager.isPresent() ? wager.get().getPool() : null))
.setCellStyle(commaNumberFormat);
}
}
}