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


Java XSSFCell.setCellValue方法代碼示例

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


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

示例1: writeXLSXFile

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的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: updateCellValue

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
public void updateCellValue(String cellPosition, String value) throws Exception {
    
    String sheetNumTxt = cellPosition.indexOf("[")>-1 ? cellPosition.substring(cellPosition.indexOf("[")) : null;
        if(sheetNumTxt != null) {
            this.sheetNum = new Integer(sheetNumTxt.substring(0,sheetNumTxt.length()-1));
            cellPosition = cellPosition.substring(cellPosition.indexOf("["));
        } else {
            this.sheetNum = 0;
        }
        worksheet = workbook.getSheetAt(this.sheetNum);
    
    CellReference c = new CellReference(cellPosition);
    XSSFCell cell = worksheet.getRow(c.getRow()).getCell(c.getCol());
    if(cell == null) throw new Exception("Invalid cell reference:" + cellPosition);
    if(value == null) {
       cell.setCellType(XSSFCell.CELL_TYPE_BLANK);
    } else if(cell.getCellType()==XSSFCell.CELL_TYPE_FORMULA) {
        this.setCellFormula(cell, value);
    } else {
        cell.setCellValue(value);
    }
}
 
開發者ID:linearblue,項目名稱:ExcelInjector,代碼行數:23,代碼來源:ExcelTableInjector.java

示例3: createXLSXModifyProtected

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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: setCellProperties

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param cell
 * @param value
 * @param style
 */
public static void setCellProperties(XSSFCell cell, String value,
		XSSFCellStyle style) {
	Assert.notNull(cell, "cell must not be null!");
	// fill year
	cell.setCellValue(value);
	cell.setCellStyle(style);
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:13,代碼來源:CellValueUtil.java

示例11: setCellProperties

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param cell
 * @param value
 * @param style
 */
public static void setCellProperties(XSSFCell cell,String value,XSSFCellStyle style){
	Assert.notNull(cell, "cell must not be null!");
	//fill year
	cell.setCellValue(value);
	cell.setCellStyle(style);
}
 
開發者ID:gp15237125756,項目名稱:PoiExcelExport,代碼行數:12,代碼來源:XSSFCellUtil.java

示例12: asNumber

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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.XSSFCell; //導入方法依賴的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: copyCell

import org.apache.poi.xssf.usermodel.XSSFCell; //導入方法依賴的package包/類
/**
 * @param oldCell
 * @param newCell
 * @param styleMap
 */
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, XSSFCellStyle> styleMap) {
    if (styleMap != null) {
        if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
            newCell.setCellStyle(oldCell.getCellStyle());
        } else {
            int stHashCode = oldCell.getCellStyle().hashCode();
            XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
            if (newCellStyle == null) {
                newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
                newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
                styleMap.put(stHashCode, newCellStyle);
            }
            newCell.setCellStyle(newCellStyle);
        }
    }
    switch (oldCell.getCellType()) {
        case XSSFCell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getStringCellValue());
            break;
        case XSSFCell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case XSSFCell.CELL_TYPE_BLANK:
            newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
            break;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case XSSFCell.CELL_TYPE_ERROR:
            newCell.setCellErrorValue(oldCell.getErrorCellValue());
            break;
        case XSSFCell.CELL_TYPE_FORMULA:
            newCell.setCellFormula(oldCell.getCellFormula());
            break;
        default:
            break;
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:45,代碼來源:Util.java


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