当前位置: 首页>>代码示例>>Java>>正文


Java XSSFRow.createCell方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFRow.createCell方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFRow.createCell方法的具体用法?Java XSSFRow.createCell怎么用?Java XSSFRow.createCell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFRow的用法示例。


在下文中一共展示了XSSFRow.createCell方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeXLSXFile

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的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

示例2: copyRow

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
/**
 * @param srcSheet the sheet to copy.
 * @param destSheet the sheet to create.
 * @param srcRow the row to copy.
 * @param destRow the row to create.
 * @param styleMap -
 */
public static void copyRow(XSSFSheet srcSheet, XSSFSheet destSheet, XSSFRow srcRow, XSSFRow destRow, Map<Integer, XSSFCellStyle> styleMap) {
    // manage a list of merged zone in order to not insert two times a merged zone  
    Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
    destRow.setHeight(srcRow.getHeight());
    // pour chaque row  
    for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
        if(j<0){
        }else{
            XSSFCell oldCell = srcRow.getCell(j);   // ancienne cell  
        XSSFCell newCell = destRow.getCell(j);  // new cell   
        if (oldCell != null) {
            if (newCell == null) {
                newCell = destRow.createCell(j);
            }
            // copy chaque cell  
            copyCell(oldCell, newCell, styleMap);
                  // copy les informations de fusion entre les cellules  
            //System.out.println("row num: " + srcRow.getRowNum() + " , col: " + (short)oldCell.getColumnIndex());  
            CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(), (short) oldCell.getColumnIndex());

            if (mergedRegion != null) {
                //System.out.println("Selected merged region: " + mergedRegion.toString());  
                CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(), mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
                //System.out.println("New merged region: " + newMergedRegion.toString());  
                CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                if (isNewMergedRegion(wrapper, mergedRegions)) {
                    mergedRegions.add(wrapper);
                    destSheet.addMergedRegion(wrapper.range);
                }
            }
        }
        }
        
    }

}
 
开发者ID:likelet,项目名称:DAtools,代码行数:44,代码来源:Util.java

示例3: createXLSXModifyProtected

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
@Test
   public void createXLSXModifyProtected() throws IOException {
System.out.println("createXLSXModifyProtected");

//creates sheet
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("Gravado");
sheet.protectSheet("54321");

//saves sheet
new File("target/.output-file/xlsx").mkdirs();
workbook.write(new FileOutputStream("target/.output-file/xlsx/ModifyProtected.xlsx"));

//read again and check
XSSFWorkbook workbook2 = new XSSFWorkbook(new FileInputStream("target/.output-file/xlsx/ModifyProtected.xlsx"));
Assert.assertEquals("Gravado", workbook2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
   }
 
开发者ID:utluiz,项目名称:poi-security,代码行数:21,代码来源:EncryptXlsxTests.java

示例4: fillExtraFields

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private void fillExtraFields(String tablename, Object id, XSSFRow row, LinkedHashSet<String> de, int startCol) throws SQLException {
	// ExtraFields
	if (id != null && de != null) {
		String sql = "Select * from " + MyDBI.delimitL("ExtraFields") + " WHERE " + MyDBI.delimitL("tablename") + "='" + tablename  + "' AND " + MyDBI.delimitL("id") + "=" + id;
		ResultSet rs2 = DBKernel.getResultSet(sql, false);
		if (rs2 != null && rs2.first()) {
			do {
				String s = rs2.getString("attribute");
				int j=0;
				for (String e : de) {
					if (s.equalsIgnoreCase(e)) {
						XSSFCell cell = row.getCell(startCol+j);
						if (cell == null) cell = row.createCell(startCol+j);
						cell.setCellValue(rs2.getString("value"));
						break;
					}
					j++;
				}
			} while (rs2.next());
		}	
	}		
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:23,代码来源:TraceGenerator.java

示例5: writeSheet

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook){
	XSSFSheet worksheet = workbook.createSheet(key);
	int count=0;//keeps track of rows; one below the row int because of header row
	final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$");
	//for each row, create the row in excel
	for (int row=0; row<sheetVector.size();row++){
		XSSFRow row1 = worksheet.createRow( count);
		count++;
		//for each col, write it to that row.
		for (int col=0; col<sheetVector.get(0).length;col++){
			XSSFCell cell = row1.createCell(col);
			String val = sheetVector.get(row)[col];
			if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) {
				cell.setCellType(Cell.CELL_TYPE_NUMERIC);
				cell.setCellValue(Double.parseDouble(val));
				continue;
			}
			cell.setCellValue(sheetVector.get(row)[col]);
		}
	}
}
 
开发者ID:SEMOSS,项目名称:semoss,代码行数:22,代码来源:POIWriter.java

示例6: writeSheet

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook) {
	XSSFSheet worksheet = workbook.createSheet(key);
	int count=0;//keeps track of rows; one below the row int because of header row
	final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$");
	//for each row, create the row in excel
	for (int row=0; row<sheetVector.size();row++){
		XSSFRow row1 = worksheet.createRow( count);
		count++;
		//for each col, write it to that row.7
		for (int col=0; col<sheetVector.get(row).length;col++) {
			XSSFCell cell = row1.createCell(col);
			if(sheetVector.get(row)[col] != null) {
				String val = sheetVector.get(row)[col];
				//Check if entire value is numeric - if so, set cell type and parseDouble, else write normally
				if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) {
					cell.setCellType(Cell.CELL_TYPE_NUMERIC);
					cell.setCellValue(Double.parseDouble(val));
				} else {
					cell.setCellValue(sheetVector.get(row)[col].replace("\"", ""));
				}
			}
		}
	}
}
 
开发者ID:SEMOSS,项目名称:semoss,代码行数:25,代码来源:RelationshipLoadingSheetWriter.java

示例7: writeSheet

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook) {
	XSSFSheet worksheet = workbook.createSheet(key);
	int count=0;//keeps track of rows; one below the row int because of header row
	final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$");
	//for each row, create the row in excel
	for (int row=0; row<sheetVector.size();row++){
		XSSFRow row1 = worksheet.createRow( count);
		count++;
		//for each col, write it to that row.7
		for (int col=0; col<sheetVector.get(row).length;col++){
			XSSFCell cell = row1.createCell(col);
			if(sheetVector.get(row)[col] != null) {
				String val = sheetVector.get(row)[col];
				//Check if entire value is numeric - if so, set cell type and parseDouble, else write normally
				if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) {
					cell.setCellType(Cell.CELL_TYPE_NUMERIC);
					cell.setCellValue(Double.parseDouble(val));
				} else {
					cell.setCellValue(sheetVector.get(row)[col].replace("\"", ""));
				}
			}
		}
	}
}
 
开发者ID:SEMOSS,项目名称:semoss,代码行数:25,代码来源:NodeLoadingSheetWriter.java

示例8: printHeader

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
@Override
protected void printHeader(List<String> header, ByteArrayOutputStream out) {
	wb = new XSSFWorkbook();
       sheet = wb.createSheet("NextReports");

       XSSFRow headerRow = sheet.createRow(0);
       int col = 0;        
	if (header != null) {
		for (String s : header) {
			XSSFCell cell = headerRow.createCell(col);
			cell.setCellType(XSSFCell.CELL_TYPE_STRING);
			if (s == null) {
				s = "";
			}
			cell.setCellValue(wb.getCreationHelper().createRichTextString(s));
			col++;
		}
	}		
}
 
开发者ID:nextreports,项目名称:nextreports-server,代码行数:20,代码来源:XlsxResource.java

示例9: convertToXSSFWorkbook

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFWorkbook convertToXSSFWorkbook(String html)
{
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Sheet1");
    Document doc = Jsoup.parse(html);
    for (Element table : doc.select("table")) {
        int rownum = 0;
        for (Element row : table.select("tr")) {
            XSSFRow exlrow = sheet.createRow(rownum++);
            int cellnum = 0;
            for (Element tds : row.select("td")) {
                StringUtils.isNumeric("");
                XSSFCell cell = exlrow.createCell(cellnum++);
                cell.setCellValue(tds.text());
            }
        }
    }
    return workbook;
}
 
开发者ID:ameyjadiye,项目名称:HtmlToExcel,代码行数:20,代码来源:HtmlToExcel.java

示例10: createCellIfNotPresent

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell createCellIfNotPresent(XSSFRow row, int colIndex) {
	String message = "XSSFRow must not be null!";
	Objects.requireNonNull(row, () -> message);
	XSSFCell cell = row.getCell(colIndex);
	if (Objects.isNull(cell)) {
		cell = row.createCell(colIndex);
	}
	return cell;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:10,代码来源:CellValueUtil.java

示例11: createCellIfNotPresent

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell createCellIfNotPresent(XSSFRow row,int colIndex){
	String message="XSSFRow must not be null!";
	Objects.requireNonNull(row, () -> message);
	XSSFCell cell=row.getCell(colIndex);
	if(Objects.isNull(cell)){
		cell=row.createCell(colIndex);
	}
	return cell;
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:10,代码来源:XSSFCellUtil.java

示例12: asNumber

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell asNumber(XSSFRow row, int columnIndex, Number value) {
    XSSFCell cell = row.createCell(columnIndex, Cell.CELL_TYPE_NUMERIC);
    if (value != null) {
        cell.setCellValue(value.doubleValue());
    }
    return cell;
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:8,代码来源:XSSFCellCreator.java

示例13: asText

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell asText(XSSFRow row, int columnIndex, Object value) {
    XSSFCell cell = row.createCell(columnIndex, Cell.CELL_TYPE_STRING);
    if (value != null) {
        cell.setCellValue((String) value);
    }
    return cell;
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:8,代码来源:XSSFCellCreator.java

示例14: asDate

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
public static XSSFCell asDate(XSSFRow row, int columnIndex, LocalDate localDate) {
    XSSFCell cell = row.createCell(columnIndex, Cell.CELL_TYPE_STRING);
    if (localDate != null) {
        Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
        cell.setCellValue(date);
    }
    return cell;
}
 
开发者ID:robinhowlett,项目名称:handycapper,代码行数:9,代码来源:XSSFCellCreator.java

示例15: shiftRange

import org.apache.poi.xssf.usermodel.XSSFRow; //导入方法依赖的package包/类
private void shiftRange(int numRowsDown, int rowStart, int rowEnd, int colStart, int colEnd) throws Exception {
        // loop through from bottom row up to either SHIFT the whole row, or copy necessary columns, insert  new row below, insert the data from the cell and then delete all style and format from the original cell
        for(int j=rowEnd;j>rowStart;j--) {
            XSSFRow row = worksheet.getRow(j);
            XSSFRow newRow = worksheet.getRow(j+numRowsDown);
            if(row == null && newRow == null) 
                continue;
            else if (row == null) {
                worksheet.removeRow(newRow);
                continue;
            }
            if(newRow == null) {
                newRow = worksheet.createRow(j+numRowsDown);
            }
//            newRow = worksheet.getRow(j+numRowsDown);
            //if(row ==null) continue;
            for(int k=colStart;k<=colEnd;k++) {
                XSSFCell cell = row.getCell(k);
                if(cell != null) {
                    XSSFCell newCell = newRow.getCell(k)==null ? newRow.createCell(k) : newRow.getCell(k);
                    if(cell==null) continue;
                    if(cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) {
                        String calc = cell.getCellFormula();
                        newCell.setCellStyle(cell.getCellStyle());
                        cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
                        this.setCellFormula(newCell, calc);
                    } else if(cell.getCellType()==XSSFCell.CELL_TYPE_BLANK) {
                        newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
                    } else {
                        newCell.copyCellFrom(cell, new CellCopyPolicy());
                        newCell.setCellStyle(cell.getCellStyle());
                    }
                }
            }
        }
    }
 
开发者ID:linearblue,项目名称:ExcelInjector,代码行数:37,代码来源:ExcelTableInjector.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFRow.createCell方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。