本文整理匯總了Java中org.apache.poi.xssf.usermodel.XSSFSheet.createRow方法的典型用法代碼示例。如果您正苦於以下問題:Java XSSFSheet.createRow方法的具體用法?Java XSSFSheet.createRow怎麽用?Java XSSFSheet.createRow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.xssf.usermodel.XSSFSheet
的用法示例。
在下文中一共展示了XSSFSheet.createRow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeXLSXFile
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的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();
}
示例2: createWageringHeaderRow
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public static XSSFRow createWageringHeaderRow(XSSFSheet sheet, int row, int col) {
XSSFRow headerRow = sheet.createRow(row++);
col = seedCols(col, headerRow);
List<String> columns = Arrays.asList("winPayoff", "placePayoff",
"showPayoff", "totalWpsPool", "doublePayoff", "doublePool", "exactaPayoff",
"exactaPool", "trifectaPayoff", "trifectaPool", "superfectaPayoff",
"superfectaPool", "pick3Payoff", "pick3Pool", "pick4Payoff", "pick4Pool",
"pick5Payoff", "pick5Pool");
for (String column : columns) {
CellUtil.createCell(headerRow, col++, column);
}
return headerRow;
}
示例3: copySheets
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* @param newSheet the sheet to create from the copy.
* @param sheet the sheet to copy.
* @param copyStyle true copy the style.
*/
public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) {
int maxColumnNum = 0;
Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null;
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
XSSFRow srcRow = sheet.getRow(i);
XSSFRow destRow = newSheet.createRow(i);
if (srcRow != null) {
Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap);
if (srcRow.getLastCellNum() > maxColumnNum) {
maxColumnNum = srcRow.getLastCellNum();
}
}
}
for (int i = 0; i <= maxColumnNum; i++) {
newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
}
//Util.copyPictures(newSheet,sheet) ;
}
示例4: generate
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public XSSFWorkbook generate(List<Person> persons, List<String> columns) {
XSSFSheet sheet = (XSSFSheet) createSheet("Document .xlsx");
int rowIndex = 0;
addHeadersToSheet(sheet, rowIndex, columns);
rowIndex++;
for (Person person : persons) {
XSSFRow currentRow = sheet.createRow(rowIndex);
rowIndex++;
int columnIndex = 0;
for (String column : columns) {
addCell(currentRow, columnIndex, person, column);
columnIndex++;
}
}
finalizeSheet(sheet, columns);
return (XSSFWorkbook) workbook;
}
示例5: getCell
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* Returns the cell of a given sheet at icol;irow. Former values are overwritten.
*
* @param sheet the sheet to write on
* @param icol index of column
* @param irow index of row
* @return the given cell at icol;irow
* @see
*/
public Cell getCell(XSSFSheet sheet, int icol, int irow) {
// try to get row
Row row = sheet.getRow(irow);
// if not exist: create row
if (row == null)
row = sheet.createRow(irow);
// get cell
return row.createCell(icol);
}
示例6: writeToSheet
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* Adds the given information as a new row to the provided sheet
* @param data: an array of strings to write to different cells of a new row in the sheet
* * @see SHEET_METADATA
*/
public void writeToSheet(String[] data, int SHEET){
XSSFSheet sheet;
Row row;
//Get the sheet and the next row to edit on that sheet
switch(SHEET)
{
case SHEET_COMMENTS:
sheet = commentSheet;
row = sheet.createRow(commentRowCount++);
//Custom row stylings for Comment Sheet entries
row.setRowStyle(styleWordWrap);
row.setHeight((short)850);
break;
case SHEET_METADATA:
sheet = metadataSheet;
row = sheet.createRow(metadataRowCount++);
//Custom row stylings for Plant Metadata Sheet entries
break;
case SHEET_BEDMETADATA:
sheet = bedmetadataSheet;
row = sheet.createRow(bedmetadataRowCount++);
//Custom row stylings for Bed Metadata Sheet entries
break;
default:
throw new IndexOutOfBoundsException("Sheet " + SHEET + " not understood, getSHEET is being called with incorrect input.");
}
//Write the data
for(int i = 0; i < data.length; i++) {
Cell cell = row.createCell(i);
cell.setCellValue(data[i]);
}
}
開發者ID:UMM-CSci-3601-S17,項目名稱:digital-display-garden-iteration-4-revolverenguardia-1,代碼行數:44,代碼來源:FeedbackWriter.java
示例7: createHeader
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
private void createHeader(Map<String, CellStyle> styles,
XSSFSheet sheet,
List<String> header) {
final XSSFRow rowhead = sheet.createRow(0);
int i = 0;
for (String headerColumn : header) {
rowhead.createCell(i).setCellValue(new XSSFRichTextString(headerColumn));
rowhead.getCell(i).setCellStyle(styles.get("header"));
i++;
}
}
示例8: createBreedingHeaderRow
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public static XSSFRow createBreedingHeaderRow(XSSFSheet sheet, int row, int col) {
XSSFRow headerRow = sheet.createRow(row++);
col = standardCols(col, headerRow);
List<String> columns = Arrays.asList("sex", "sire", "dam", "damSire", "foalDate", "age");
for (String column : columns) {
CellUtil.createCell(headerRow, col++, column);
}
return headerRow;
}
示例9: createNewWorkbook
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* Creates a new workbook.
*
* @param map
* the map of path, key, locales and properties
* @return the workbook
*/
private Workbook createNewWorkbook(final Map<PathAndKey, Map<Locale, String>> map) {
int rowCounter = 0;
final XSSFWorkbook workbook = new XSSFWorkbook();
final XSSFSheet worksheet = workbook.createSheet("Worksheet");
XSSFRow currentRow = worksheet.createRow(rowCounter++);
int cellCounter = 0;
final List<Locale> locales = findAllLocales(map);
// create header
currentRow.createCell(cellCounter++).setCellValue("path");
currentRow.createCell(cellCounter++).setCellValue("key");
currentRow.createCell(cellCounter++).setCellValue("used");
for (final Locale locale : locales) {
currentRow.createCell(cellCounter++).setCellValue(locale.toString());
}
// fill in values
for (final Entry<PathAndKey, Map<Locale, String>> e : map.entrySet()) {
currentRow = worksheet.createRow(rowCounter++);
fillNewRow(currentRow, e, locales);
}
return workbook;
}
示例10: writeToSheet
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public void writeToSheet(String sheetName, Map<Integer,String> cellValues, Map<Integer,String> headerValues){
XSSFSheet sheet;
if(sheetNames.contains(sheetName)){
sheet = wb.getSheet(sheetName);
}
else{
sheet = wb.createSheet(sheetName);
sheetNames.add(sheetName);
}
setRowNumber(headerValues);
XSSFRow row = sheet.createRow(lastRow);
for(int i : cellValues.keySet()){
XSSFCell cell = row.createCell(i);
cell.setCellValue(cellValues.get(i));
}
XSSFRow headerRow = sheet.getRow(0);
if(headerRow == null);
headerRow = sheet.createRow(0);
for(int j : headerValues.keySet()){
XSSFCell headerCell = headerRow.createCell(j);
headerCell.setCellValue(headerValues.get(j));
}
incRowNumber(headerValues);
}
示例11: writeExcel
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public static void writeExcel(HttpServletResponse response,List<String> list) throws Exception {
response.setContentType("application/vnd.ms-excel");//文件格式,此處設置為excel
response.setHeader("Content-Disposition","attachment;filename=file.xls");//此處設置了下載文件的默認名稱
ServletOutputStream sos = response.getOutputStream();
//創建一個新的excel
XSSFWorkbook wb = new XSSFWorkbook();//XSSFWorkbook
/**
* 采用現成Excel模板
* 用這種方式得先保證每個cell有值,不然會報空指針
* 有時我們用row.getCell(i)會得到null,那麽此時就要用Iterator<Cell> it = row.cellIterator();
* XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(new File("D://a.xlsx")));
* XSSFSheet sheet = wb.getSheet("Sheet1");
* row[i] = sheet.getRow(i);
* headerCell[j] = row[i].getCell(j);
*/
//創建sheet頁
XSSFSheet sheet = wb.createSheet("sheet1");//sheet名
//創建行數
XSSFRow[] row = new XSSFRow[list.size()];
//插入數據
for (int i = 0; i < row.length; i++) {
row[i] = sheet.createRow(i);
sheet.setDefaultColumnWidth(30);//設置列的長度
String info[] = list.get(i).split(",");
XSSFCell[] headerCell = new XSSFCell[info.length];
for (int j = 0; j < headerCell.length; j++) {
headerCell[j] = row[i].createCell(j);
headerCell[j].setCellValue(new XSSFRichTextString(info[j]));
/**設置模板樣式*/
//headerCell[j].setCellStyle(setStyle(wb));
}
}
wb.write(sos);
wb.close();
sos.flush();
sos.close();
response.flushBuffer();
}
示例12: buildSpreadsheet
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* Construye la hoja de Excel
*
* @return Instancia de la clase XSSFWorkbook con los datos almacenados en
* el buffer de datos
*/
private XSSFWorkbook buildSpreadsheet() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
for (int i = 0; i <= mainBuffer.get(0).size(); i++) {
Row row = sheet.createRow(i);
for (int j = 0; j < variableList.size(); j++) {
Cell cell = row.createCell(j);
if (i == 0) {
cell.setCellValue((String) variableList.get(j));
} else {
Object value = classList.get(j);
if ((value instanceof String) || (value.equals(String.class))) {
cell.setCellValue((String) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Boolean) || (value.equals(Boolean.class))) {
cell.setCellValue((Boolean) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Date) || (value.equals(Date.class))) {
cell.setCellValue((String) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Integer) || (value.equals(Integer.class))) {
cell.setCellValue((Integer) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Long) || (value.equals(Long.class))) {
cell.setCellValue((Long) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Float) || (value.equals(Float.class))) {
cell.setCellValue((Float) mainBuffer.get(j).get(i - 1));
} else if ((value instanceof Double) || (value.equals(Double.class))) {
cell.setCellValue((Double) mainBuffer.get(j).get(i - 1));
}
}
}
}
return workbook;
}
示例13: expReportQueryData
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
/**
* 導出數據,用scroll執行,否則大量分頁數據會有重複
* @param dataIndex 行數
* @param row HSSFRow
* @param sheet HSSFSheet
* @param req PagerReq
*/
@Override
public void expReportQueryData(PagerReq req, int dataIndex, XSSFRow row, XSSFSheet sheet) {
Query query = null;
List<Condition> conList = JSON.parseArray(req.getCondition(), Condition.class);
/* 在此處根據傳過來的trueSql去找到正確的SQl然後拚條件condition */
String sql = req.getBaseSql();
query = baseDao.getSqlQuery(sql);
for (Condition con : conList) {
query.setParameter(con.getName(), con.getValue());
}
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
/* 格式化百分號 */
String[] findex = getFIndex(req);
int i = dataIndex;
ScrollableResults scrollableResults = query.scroll();
while (scrollableResults.next()) {
Object[] list = scrollableResults.get();
row = sheet.createRow(i);
for (int j = 0; j < list.length; j++) {
if (list[j] instanceof Timestamp) {
list[j] = df.format((Timestamp) list[j]);
}
String cel = getCelValue (list[j], findex, j);
row.createCell(j).setCellValue(cel);
}
i++;
//if (i > 65535)
//break;
}
}
示例14: printSheet
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
private void printSheet(final XSSFWorkbook wb, final XSSFSheet sheet, final APIModel api) {
////////////////////////////////////////////////////
XSSFRow row = null;
XSSFCell cell = null;
////////////////////////////////////////////////////
row = sheet.createRow(1); //////////////////////////
cell = row.createCell(1, Cell.CELL_TYPE_STRING);
cell.setCellValue("機能名");
cell = row.createCell(5, Cell.CELL_TYPE_STRING);
cell.setCellValue(s(api.getName()));
cell = row.createCell(22, Cell.CELL_TYPE_STRING);
cell.setCellValue("文字コード");
cell = row.createCell(25, Cell.CELL_TYPE_STRING);
cell.setCellValue("TUF-8");
row = sheet.createRow(2); //////////////////////////
cell = row.createCell(1, Cell.CELL_TYPE_STRING);
cell.setCellValue("URL");
cell = row.createCell(5, Cell.CELL_TYPE_STRING);
cell.setCellValue(s(api.getPath()));
cell = row.createCell(15, Cell.CELL_TYPE_STRING);
cell.setCellValue("メソッド");
cell = row.createCell(18, Cell.CELL_TYPE_STRING);
cell.setCellValue("");
}
示例15: writeExcel
import org.apache.poi.xssf.usermodel.XSSFSheet; //導入方法依賴的package包/類
public void writeExcel(File file) {
//Blank workbook
XSSFWorkbook workbook = new XSSFWorkbook();
//Create a blank sheet
XSSFSheet sheet = workbook.createSheet("Employee Data");
//This data needs to be written (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
data.put("2", new Object[] {1, "Amit", "Shukla"});
data.put("3", new Object[] {2, "Lokesh", "Gupta"});
data.put("4", new Object[] {3, "John", "Adwards"});
data.put("5", new Object[] {4, "Brian", "Schultz"});
//Iterate over data and write to sheet
Set<String> keyset = data.keySet();
int rownum = 0;
for (String key : keyset) {
Row row = sheet.createRow(rownum++);
Object[] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr)
{
Cell cell = row.createCell(cellnum++);
if (obj instanceof String)
cell.setCellValue((String)obj);
else if (obj instanceof Integer)
cell.setCellValue((Integer)obj);
}
}
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
//Write the workbook in file system
workbook.write(fileOutputStream);
logger.debug("{} written successfully on disk.", file.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}