use of org.apache.poi.xssf.usermodel.XSSFRow in project TeachingInSimulation by ScOrPiOzzy.
the class ExcelUtil method readExcelCell07.
private static Object[][] readExcelCell07(Workbook wb, String sheetName, int rowNum, int columnNum) throws Exception {
Object[][] result = null;
int cellType = 0;
XSSFRow row = null;
XSSFCell cell = null;
result = new Object[rowNum][columnNum];
XSSFSheet sheet = (XSSFSheet) wb.getSheet(sheetName);
// 开始循环遍历单元格,取出数据放入result的二维数组中
for (int i = START_ROW; i < rowNum; i++) {
row = sheet.getRow(i);
cellType = -1;
Object cellValue = null;
// 确保此行有数据
if (row == null) {
result[i] = null;
continue;
}
boolean rowEmptyFlg = true;
for (int j = 0; j < columnNum; j++) {
cell = row.getCell(j);
if (cell != null) {
rowEmptyFlg = false;
// 判断单元格内数据类型,
try {
// 數字型必須要先檢測,他既不會走if也不會走catch
cellType = cell.getCellType();
if (DateUtil.isCellDateFormatted(cell)) {
// 日期格式需要这样来判断,下面的方法判断不了
cellType = CELL_TYPE_DATE;
}
} catch (IllegalStateException e) {
cellType = cell.getCellType();
}
if (cellType == CELL_TYPE_NULL) {
// 空值型
result[i][j] = null;
continue;
} else if (cellType == CELL_TYPE_NUM) {
// 数值型,避免科学计数法
DecimalFormat df = new DecimalFormat("0");
cellValue = df.format(cell.getNumericCellValue());
} else if (cellType == CEll_TYPE_STRING) {
// 字符串型
cellValue = cell.getStringCellValue();
} else if (cellType == CELL_TYPE_BOOLEAN) {
// boolean型
cellValue = new Boolean(cell.getBooleanCellValue());
} else if (cellType == CELL_TYPE_DATE) {
// 日期类型
double value = cell.getNumericCellValue();
cellValue = DateUtil.getJavaDate(value);
} else if (cellType == CEll_TYPE_EXPRESSION) {
cellValue = cell.getCTCell().getV();
// cellValue = cell.getNumericCellValue();
}
result[i][j] = cellValue;
} else {
result[i][j] = null;
}
}
// 如何该行每一列都没有数据,则该行为空
if (rowEmptyFlg) {
result[i] = null;
}
}
return result;
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dhis2-core by dhis2.
the class ExcelNodeSerializer method startWriteRootNode.
@Override
protected void startWriteRootNode(RootNode rootNode) throws Exception {
XSSFCreationHelper creationHelper = workbook.getCreationHelper();
int rowIdx = 1;
for (Node collectionNode : rootNode.getChildren()) {
if (collectionNode.isCollection()) {
for (Node complexNode : collectionNode.getChildren()) {
XSSFRow row = sheet.createRow(rowIdx++);
int cellIdx = 0;
for (Node node : complexNode.getChildren()) {
if (node.isSimple()) {
XSSFCell cell = row.createCell(cellIdx++);
cell.setCellValue(getValue((SimpleNode) node));
if (node.haveProperty() && PropertyType.URL.equals(node.getProperty().getPropertyType())) {
XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
hyperlink.setAddress(getValue((SimpleNode) node));
hyperlink.setLabel(getValue((SimpleNode) node));
cell.setHyperlink(hyperlink);
} else if (node.haveProperty() && PropertyType.EMAIL.equals(node.getProperty().getPropertyType())) {
XSSFHyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.EMAIL);
hyperlink.setAddress(getValue((SimpleNode) node));
hyperlink.setLabel(getValue((SimpleNode) node));
cell.setHyperlink(hyperlink);
}
}
}
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project dhis2-core by dhis2.
the class ExcelNodeSerializer method startSerialize.
@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
workbook = new XSSFWorkbook();
sheet = workbook.createSheet("Sheet1");
XSSFFont boldFont = workbook.createFont();
boldFont.setBold(true);
XSSFCellStyle boldCellStyle = workbook.createCellStyle();
boldCellStyle.setFont(boldFont);
// build schema
for (Node child : rootNode.getChildren()) {
if (child.isCollection()) {
if (!child.getChildren().isEmpty()) {
Node node = child.getChildren().get(0);
XSSFRow row = sheet.createRow(0);
int cellIdx = 0;
for (Node property : node.getChildren()) {
if (property.isSimple()) {
XSSFCell cell = row.createCell(cellIdx++);
cell.setCellValue(property.getName());
cell.setCellStyle(boldCellStyle);
}
}
}
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project CodeUtils by boredream.
the class OfficeUtils method main.
public static void main(String[] args) {
File file = new File("temp" + File.separator + "office" + File.separator + "maidian.xlsx");
XSSFWorkbook xssfWorkbook = openXlsx(file);
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
int totalRows = xssfSheet.getPhysicalNumberOfRows();
for (int rowNum = 2; rowNum < totalRows; rowNum++) {
XSSFRow row = xssfSheet.getRow(rowNum);
int cellNum = row.getLastCellNum();
if (cellNum == 6) {
String name = getCellString(row.getCell(4));
String eventid = getCellString(row.getCell(5));
// /**
// * aa
// */
// public static final String a = "a";
System.out.println("/**");
System.out.println(" * " + name);
System.out.println(" */");
System.out.println("public static final String " + eventid.toUpperCase() + " = \"" + eventid + "\"");
System.out.println();
}
}
}
use of org.apache.poi.xssf.usermodel.XSSFRow in project data-prep by Talend.
the class ExcelComparator method compareTwoSheets.
// Compare Two Sheets
public static boolean compareTwoSheets(XSSFSheet sheet1, XSSFSheet sheet2) {
int firstRow1 = sheet1.getFirstRowNum();
int lastRow1 = sheet1.getLastRowNum();
boolean equalSheets = true;
for (int i = firstRow1; i <= lastRow1; i++) {
XSSFRow row1 = sheet1.getRow(i);
XSSFRow row2 = sheet2.getRow(i);
if (!compareTwoRows(row1, row2)) {
equalSheets = false;
break;
}
}
return equalSheets;
}
Aggregations