Java Code Examples for org.apache.poi.hssf.usermodel.HSSFRow

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFRow. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: easyexcel   Source File: StyleTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void poi() throws Exception {
    InputStream is = new FileInputStream("D:\\test\\styleTest.xls");
    HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
    HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(0);
    HSSFRow hssfRow = hssfSheet.getRow(0);
    System.out.println(hssfRow.getCell(0).getCellStyle().getDataFormatString());
    DataFormatter formatter = new DataFormatter();
    System.out.println(hssfRow.getCell(0).getNumericCellValue());
    System.out.println(hssfRow.getCell(1).getNumericCellValue());
    System.out.println(hssfRow.getCell(2).getNumericCellValue());
    System.out.println(hssfRow.getCell(0).getCellStyle().getDataFormatString());
    System.out.println(hssfRow.getCell(1).getCellStyle().getDataFormatString());
    System.out.println(hssfRow.getCell(2).getCellStyle().getDataFormatString());

}
 
Example 2
Source Project: nextreports-server   Source File: XlsResource.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void printHeader(List<String> header, ByteArrayOutputStream out) {
	wb = new HSSFWorkbook();
       sheet = wb.createSheet("NextReports");

       HSSFRow headerRow = sheet.createRow(0);
       int col = 0;        
	if (header != null) {
		for (String s : header) {
			HSSFCell cell = headerRow.createCell(col);
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			if (s == null) {
				s = "";
			}
			cell.setCellValue(new HSSFRichTextString(s));
			col++;
		}
	}		
}
 
Example 3
Source Project: neoscada   Source File: ExportEventsImpl.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
    final Font font = sheet.getWorkbook ().createFont ();
    font.setFontName ( "Arial" );
    font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
    font.setColor ( HSSFColor.WHITE.index );

    final CellStyle style = sheet.getWorkbook ().createCellStyle ();
    style.setFont ( font );
    style.setFillForegroundColor ( HSSFColor.BLACK.index );
    style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );

    final HSSFRow row = sheet.createRow ( 0 );

    for ( int i = 0; i < columns.size (); i++ )
    {
        final Field field = columns.get ( i );

        final HSSFCell cell = row.createCell ( i );
        cell.setCellValue ( field.getHeader () );
        cell.setCellStyle ( style );
    }
}
 
Example 4
Source Project: ermaster-b   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String getCellValue(HSSFSheet sheet, int r, int c) {
	HSSFRow row = sheet.getRow(r);
	
	if (row == null) {
		return null;
	}
	
	HSSFCell cell = row.getCell(c);
	
	if (cell == null) {
		return null;
	}
	
	HSSFRichTextString cellValue = cell.getRichStringCellValue();

	return cellValue.toString();
}
 
Example 5
Source Project: ermaster-b   Source File: AbstractSheetGenerator.java    License: Apache License 2.0 6 votes vote down vote up
protected Map<String, String> buildKeywordsValueMap(HSSFSheet wordsSheet,
		int columnNo, String[] keywords) {
	Map<String, String> keywordsValueMap = new HashMap<String, String>();

	for (String keyword : keywords) {
		CellLocation location = POIUtils.findCell(wordsSheet, keyword,
				columnNo);
		if (location != null) {
			HSSFRow row = wordsSheet.getRow(location.r);

			HSSFCell cell = row.getCell(location.c + 2);
			String value = cell.getRichStringCellValue().getString();

			if (value != null) {
				keywordsValueMap.put(keyword, value);
			}
		}
	}

	return keywordsValueMap;
}
 
Example 6
Source Project: ermaster-b   Source File: DBUnitXLSTestDataCreator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void writeDirectTestData(ERTable table,
		Map<NormalColumn, String> data, String database) {
	HSSFRow row = this.sheet.createRow(this.rowNum++);

	int col = 0;

	for (NormalColumn column : table.getExpandedColumns()) {
		HSSFCell cell = row.createCell(col++);

		String value = Format.null2blank(data.get(column));

		if (value == null || "null".equals(value.toLowerCase())) {

		} else {
			cell.setCellValue(new HSSFRichTextString(value));
		}
	}
}
 
Example 7
Source Project: hy.common.report   Source File: ExcelHelp.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 复制行高
 * 
 * @author      ZhengWei(HY)
 * @createDate  2020-05-29
 * @version     v1.0
 *
 * @param i_FromRow
 * @param io_ToRow
 */
public final static void copyRowHeight(Row i_FromRow ,Row io_ToRow)
{
    if ( i_FromRow instanceof HSSFRow )
    {
        io_ToRow.setHeight(        ((HSSFRow)i_FromRow).getHeight());
        io_ToRow.setHeightInPoints(((HSSFRow)i_FromRow).getHeightInPoints());
        io_ToRow.setZeroHeight(    ((HSSFRow)i_FromRow).getZeroHeight());
    }
    else if ( i_FromRow instanceof SXSSFRow )
    {
        io_ToRow.setHeight(        ((SXSSFRow)i_FromRow).getHeight());
        io_ToRow.setHeightInPoints(((SXSSFRow)i_FromRow).getHeightInPoints());
        io_ToRow.setZeroHeight(    ((SXSSFRow)i_FromRow).getZeroHeight());
    }
    else if ( i_FromRow instanceof XSSFRow )
    {
        io_ToRow.setHeight(        ((XSSFRow)i_FromRow).getHeight());
        io_ToRow.setHeightInPoints(((XSSFRow)i_FromRow).getHeightInPoints());
        io_ToRow.setZeroHeight(    ((XSSFRow)i_FromRow).getZeroHeight());
    }
}
 
Example 8
@Test
public void testFastExport() throws ResourceException, ReportProcessingException, IOException {
  // This establishes a baseline for the second test using the slow export.

  final MasterReport report = DebugReportRunner.parseLocalReport( "Prd-5391.prpt", Prd5391IT.class );
  final ByteArrayOutputStream bout = new ByteArrayOutputStream();
  FastExcelReportUtil.processXls( report, bout );

  final HSSFWorkbook wb = new HSSFWorkbook( new ByteArrayInputStream( bout.toByteArray() ) );
  final HSSFSheet sheetAt = wb.getSheetAt( 0 );
  final HSSFRow row = sheetAt.getRow( 0 );
  final HSSFCell cell0 = row.getCell( 0 );

  // assert that we are in the correct export type ..
  final HSSFCellStyle cellStyle = cell0.getCellStyle();
  final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
  final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
  Assert.assertEquals( "0:0:0", fillBackgroundColorColor.getHexString() );
  Assert.assertEquals( "FFFF:8080:8080", fillForegroundColorColor.getHexString() );

  HSSFFont font = cellStyle.getFont( wb );
  Assert.assertEquals( "Times New Roman", font.getFontName() );
}
 
Example 9
protected void getStudentLines(HSSFSheet sheet) {
    int i = 2;
    HSSFRow row;
    while ((row = sheet.getRow(i)) != null) {
        StudentLine studentLine = new StudentLine();
        boolean filledWithSuccess = studentLine.fillWithSpreadsheetRow(forExecutionYear, row);

        try {
            testIt(studentLine);
        } catch (Exception e) {
            filledWithSuccess = false;
        }

        if (filledWithSuccess) {
            correctStudentLines.add(studentLine);
        } else {
            erroneousStudentLines.add(studentLine);
        }

        i++;
    }
}
 
Example 10
Source Project: ermaster-b   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CellLocation findCell(HSSFSheet sheet, String[] strs) {
	for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet
			.getLastRowNum() + 1; rowNum++) {
		HSSFRow row = sheet.getRow(rowNum);
		if (row == null) {
			continue;
		}

		for (int i = 0; i < strs.length; i++) {
			Integer colNum = findColumn(row, strs[i]);

			if (colNum != null) {
				return new CellLocation(rowNum, colNum.shortValue());
			}
		}
	}

	return null;
}
 
Example 11
Source Project: JavaWeb   Source File: FileUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void readExcel(String filePth) throws Exception {
	InputStream is = new FileInputStream(filePth);
	//创建工作薄
	//XSSFWorkbook hwb = new XSSFWorkbook(is);
	HSSFWorkbook hwb = new HSSFWorkbook(new POIFSFileSystem(is));
	//得到sheet
	for (int i = 0; i < hwb.getNumberOfSheets(); i++) {
		HSSFSheet sheet = hwb.getSheetAt(i);
		int rows = sheet.getPhysicalNumberOfRows();
		//遍历每一行
		for (int j = 0; j < rows; j++) {
			HSSFRow hr = sheet.getRow(j);
			Iterator<?> it = hr.iterator();
			while(it.hasNext()){
				String context = it.next().toString();
				System.out.println(context);
			}
		}
	}
	hwb.close();
}
 
Example 12
Source Project: phone   Source File: ExcelUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
   * 初始化表头
   * @param sheet
   * @param columnJson
   * @param rowNumber
   */
  private static void writeSheetHead(HSSFSheet sheet,JSONObject columnJson,int rowNumber){
if (logger.isDebugEnabled()) {
	logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - start"); //$NON-NLS-1$
}

Set<String> keySet = columnJson.keySet();
int cellNumber = 0;
HSSFRow row = sheet.createRow(rowNumber);
for (String k : keySet) {//k:GOODS_NO
	String name = columnJson.getString(k);//品项编码
	sheet.autoSizeColumn(cellNumber);
	HSSFCell cell = row.createCell(cellNumber++);
	cell.setCellValue(name);
}

if (logger.isDebugEnabled()) {
	logger.debug("writeSheetHead(HSSFSheet, JSONObject, int) - end"); //$NON-NLS-1$
}
  }
 
Example 13
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CellLocation findCell(final HSSFSheet sheet, final String[] strs) {
    for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
        final HSSFRow row = sheet.getRow(rowNum);
        if (row == null) {
            continue;
        }

        for (int i = 0; i < strs.length; i++) {
            final Integer colNum = findColumn(row, strs[i]);

            if (colNum != null) {
                return new CellLocation(rowNum, colNum.shortValue());
            }
        }
    }

    return null;
}
 
Example 14
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CellLocation findMatchCell(final HSSFSheet sheet, final String regexp) {
    for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
        final HSSFRow row = sheet.getRow(rowNum);
        if (row == null) {
            continue;
        }

        final Integer colNum = findMatchColumn(row, regexp);

        if (colNum != null) {
            return new CellLocation(rowNum, colNum.shortValue());
        }
    }

    return null;
}
 
Example 15
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static CellLocation findCell(final HSSFSheet sheet, final String str, final int colNum) {
    for (int rowNum = sheet.getFirstRowNum(); rowNum < sheet.getLastRowNum() + 1; rowNum++) {
        final HSSFRow row = sheet.getRow(rowNum);
        if (row == null) {
            continue;
        }

        final HSSFCell cell = row.getCell(colNum);

        if (cell == null) {
            continue;
        }
        final HSSFRichTextString cellValue = cell.getRichStringCellValue();

        if (!Check.isEmpty(cellValue.getString())) {
            if (cellValue.getString().equals(str)) {
                return new CellLocation(rowNum, (short) colNum);
            }
        }
    }

    return null;
}
 
Example 16
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static int getIntCellValue(final HSSFSheet sheet, final int r, final int c) {
    final HSSFRow row = sheet.getRow(r);
    if (row == null) {
        return 0;
    }
    final HSSFCell cell = row.getCell(c);

    try {
        if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) {
            return 0;
        }
    } catch (final RuntimeException e) {
        System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
        throw e;
    }

    return (int) cell.getNumericCellValue();
}
 
Example 17
@Test
public void testSlowExport() throws ResourceException, ReportProcessingException, IOException {
  // This establishes a baseline for the second test using the slow export.

  final MasterReport report = DebugReportRunner.parseLocalReport( "Prd-5391.prpt", Prd5391IT.class );
  final ByteArrayOutputStream bout = new ByteArrayOutputStream();
  ExcelReportUtil.createXLS( report, bout );

  final HSSFWorkbook wb = new HSSFWorkbook( new ByteArrayInputStream( bout.toByteArray() ) );
  final HSSFSheet sheetAt = wb.getSheetAt( 0 );
  final HSSFRow row = sheetAt.getRow( 0 );
  final HSSFCell cell0 = row.getCell( 0 );

  // assert that we are in the correct export type ..
  final HSSFCellStyle cellStyle = cell0.getCellStyle();
  final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
  final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
  Assert.assertEquals( "0:0:0", fillBackgroundColorColor.getHexString() );
  Assert.assertEquals( "FFFF:8080:8080", fillForegroundColorColor.getHexString() );

  HSSFFont font = cellStyle.getFont( wb );
  Assert.assertEquals( "Times New Roman", font.getFontName() );
}
 
Example 18
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void copyRow(final HSSFSheet oldSheet, final HSSFSheet newSheet, final int oldStartRowNum, final int oldEndRowNum, final int newStartRowNum) {
    final HSSFRow oldAboveRow = oldSheet.getRow(oldStartRowNum - 1);

    int newRowNum = newStartRowNum;

    for (int oldRowNum = oldStartRowNum; oldRowNum <= oldEndRowNum; oldRowNum++) {
        POIUtils.copyRow(oldSheet, newSheet, oldRowNum, newRowNum++);
    }

    final HSSFRow newTopRow = newSheet.getRow(newStartRowNum);

    if (oldAboveRow != null) {
        for (int colNum = newTopRow.getFirstCellNum(); colNum <= newTopRow.getLastCellNum(); colNum++) {
            final HSSFCell oldAboveCell = oldAboveRow.getCell(colNum);
            if (oldAboveCell != null) {
                final HSSFCell newTopCell = newTopRow.getCell(colNum);
                newTopCell.getCellStyle().setBorderTop(oldAboveCell.getCellStyle().getBorderBottom());
            }
        }
    }
}
 
Example 19
Source Project: ermasterr   Source File: POIUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static List<HSSFCellStyle> copyCellStyle(final HSSFWorkbook workbook, final HSSFRow row) {
    final List<HSSFCellStyle> cellStyleList = new ArrayList<HSSFCellStyle>();

    for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {

        final HSSFCell cell = row.getCell(colNum);
        if (cell != null) {
            final HSSFCellStyle style = cell.getCellStyle();
            final HSSFCellStyle newCellStyle = copyCellStyle(workbook, style);
            cellStyleList.add(newCellStyle);
        } else {
            cellStyleList.add(null);
        }
    }

    return cellStyleList;
}
 
Example 20
public HSSFSheet build(final SearchPhdIndividualProgramProcessBean bean) {
    HSSFSheet sheet = workbook.createSheet("Processos de doutoramento");

    setHeaders(sheet);
    List<PhdIndividualProgramProcess> processes =
            PhdIndividualProgramProcess.search(bean.getExecutionYear(), bean.getPredicates());

    int i = 2;
    for (PhdIndividualProgramProcess process : processes) {
        if (!process.isAllowedToManageProcess(Authenticate.getUser())) {
            continue;
        }

        HSSFRow row = sheet.createRow(i);

        fillRow(process, row);
        i++;
    }

    return sheet;
}
 
Example 21
public void testBug() throws ResourceException, IOException, ReportProcessingException {
  final MasterReport report = DebugReportRunner.parseGoldenSampleReport( "Prd-3889.prpt" );
  final ByteArrayOutputStream bout = new ByteArrayOutputStream();
  ExcelReportUtil.createXLS( report, bout );

  final HSSFWorkbook wb = new HSSFWorkbook( new ByteArrayInputStream( bout.toByteArray() ) );
  final HSSFSheet sheetAt = wb.getSheetAt( 0 );
  final HSSFRow row = sheetAt.getRow( 0 );
  final HSSFCell cell0 = row.getCell( 0 );

  // assert that we are in the correct export type ..
  final HSSFCellStyle cellStyle = cell0.getCellStyle();
  final HSSFColor fillBackgroundColorColor = cellStyle.getFillBackgroundColorColor();
  final HSSFColor fillForegroundColorColor = cellStyle.getFillForegroundColorColor();
  assertEquals( "0:0:0", fillBackgroundColorColor.getHexString() );
  assertEquals( "FFFF:FFFF:9999", fillForegroundColorColor.getHexString() );

  // assert that there are no extra columns ..
  final HSSFRow row8 = sheetAt.getRow( 7 );
  assertNull( row8 );

}
 
Example 22
Source Project: ermasterr   Source File: DBUnitXLSTestDataCreator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void writeDirectTestData(final ERTable table, final Map<NormalColumn, String> data, final String database) {
    final HSSFRow row = sheet.createRow(rowNum++);

    int col = 0;

    for (final NormalColumn column : table.getExpandedColumns()) {
        final HSSFCell cell = row.createCell(col++);

        final String value = Format.null2blank(data.get(column));

        if (value == null || "null".equals(value.toLowerCase())) {

        } else {
            cell.setCellValue(new HSSFRichTextString(value));
        }
    }
}
 
Example 23
Source Project: jumbune   Source File: ExportUtil.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Adds header to the sheet
 * @param worksheet the worksheet
 * @param sheetName name of sheet
 * @param title title of the sheet (can be null or empty)
 * @param attributes header attributes
 */
public static void addHeader(Worksheet worksheet, String sheetName,
		String title, List<String> attributes) {
	HSSFSheet sheet = worksheet.getSheets().get(sheetName);
	HSSFCellStyle cellStyle = worksheet.getCellStyle();
	HSSFRow row = null;
	int rowNum = 0;
	
	if (title != null && ! title.isEmpty()) {
		row = sheet.createRow(rowNum++);
		row.createCell(0).setCellValue(title);
		char y = (char) ((int) 'A' + attributes.size() - 1);
		String cell = "A1:" + y + "1";
		sheet.addMergedRegion(CellRangeAddress.valueOf(cell));
	}
	
	row = sheet.createRow(rowNum);
	for (int i=0; i<attributes.size(); i++) {
		addCell(row,cellStyle, i, attributes.get(i));
	}
}
 
Example 24
Source Project: conference-app   Source File: XlsSessionReader.java    License: MIT License 6 votes vote down vote up
private List<Session> readAllSessions(InputStream is) {
    final List<Session> result = new ArrayList<Session>();

    try {
        final POIFSFileSystem fileSystem = new POIFSFileSystem(is);
        final HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
        final HSSFSheet sheet = workBook.getSheet("Alle Tage");

        int rows = sheet.getPhysicalNumberOfRows();
        // as the row is a header we start with the second one
        for (int r = 1; r < rows; r++) {
            final HSSFRow row = sheet.getRow(r);
            if (row == null) {
                continue;
            }
            final Session session = getSessionFromRow(row, r);
            if (session != null) {
                result.add(session);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error while reading sessions from file", e);
    }
    return result;
}
 
Example 25
Source Project: ermaster-b   Source File: POIUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean getBooleanCellValue(HSSFSheet sheet, int r, int c) {
	HSSFRow row = sheet.getRow(r);
	
	if (row == null) {
		return false;
	}
	
	HSSFCell cell = row.getCell(c);
	
	if (cell == null) {
		return false;
	}
	
	return cell.getBooleanCellValue();
}
 
Example 26
public void postProcessXLS(Object document) {
	HSSFWorkbook wb = (HSSFWorkbook) document;
	HSSFSheet sheet = wb.getSheetAt(0);
	HSSFRow header = sheet.getRow(0);

	HSSFCellStyle cellStyle = wb.createCellStyle();
	cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
	cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

	for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
		HSSFCell cell = header.getCell(i);

		cell.setCellStyle(cellStyle);
	}

	Row row = sheet.createRow((short) sheet.getLastRowNum() + 3);
	Cell cellDisclaimer = row.createCell(0);
	HSSFFont customFont = wb.createFont();
	customFont.setFontHeightInPoints((short) 10);
	customFont.setFontName("Arial");
	customFont.setColor(IndexedColors.BLACK.getIndex());
	customFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
	customFont.setItalic(true);

	cellDisclaimer.setCellValue("Disclaimer");
	HSSFCellStyle cellStyleDisclaimer = wb.createCellStyle();
	cellStyleDisclaimer.setFont(customFont);
	cellDisclaimer.setCellStyle(cellStyleDisclaimer);

	Row row1 = sheet.createRow(sheet.getLastRowNum() + 2);
	Cell cellDisclaimerContent1 = row1.createCell(0);
	cellDisclaimerContent1
			.setCellValue("The information contained in this website is for information purposes only, and does not constitute, nor is it intended to constitute, the provision of financial product advice.");

	Row row2 = sheet.createRow(sheet.getLastRowNum() + 1);
	Cell cellDisclaimerContent2 = row2.createCell(0);
	cellDisclaimerContent2
			.setCellValue("This website is intended to track the investor account summary information,investments and transaction in a partcular period of time. ");

}
 
Example 27
Source Project: sun-wordtable-read   Source File: WordEmbedsTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void listEmbeds2(XWPFDocument doc) throws Exception {
	for (final PackagePart pPart : doc.getAllEmbedds()) {
		final String contentType = pPart.getContentType();
		System.out.println(contentType + "\n");
		if (contentType.equals("application/vnd.ms-excel")) {
			final HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());

			for (int sheet = 0; sheet < embeddedWorkbook.getNumberOfSheets(); sheet++) {
				final HSSFSheet activeSheet = embeddedWorkbook.getSheetAt(sheet);
				if (activeSheet.getSheetName().equalsIgnoreCase("Sheet1")) {
					for (int rowIndex = activeSheet.getFirstRowNum(); rowIndex <= activeSheet
							.getLastRowNum(); rowIndex++) {
						final HSSFRow row = activeSheet.getRow(rowIndex);
						for (int cellIndex = row.getFirstCellNum(); cellIndex <= row
								.getLastCellNum(); cellIndex++) {
							final HSSFCell cell = row.getCell(cellIndex);
							if (cell != null) {
								if (cell.getCellType() == Cell.CELL_TYPE_STRING)
									System.out.println("Row:" + rowIndex + " Cell:" + cellIndex + " = "
											+ cell.getStringCellValue());
								if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
									System.out.println("Row:" + rowIndex + " Cell:" + cellIndex + " = "
											+ cell.getNumericCellValue());

									cell.setCellValue(cell.getNumericCellValue() * 2); // update
																						// the
																						// value
								}
							}
						}
					}
				}
			}
		}
	}
}
 
Example 28
Source Project: lams   Source File: ImportService.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
   public boolean isUserSpreadsheet(MultipartFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
String string = parseStringCell(row.getCell(ImportService.PASSWORD));
return (StringUtils.equals(string, "* password")) ? true : false;
   }
 
Example 29
Source Project: lams   Source File: ImportService.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
   public boolean isRolesSpreadsheet(MultipartFile fileItem) throws IOException {
HSSFSheet sheet = getSheet(fileItem);
HSSFRow row = sheet.getRow(sheet.getFirstRowNum());
String string = parseStringCell(row.getCell(ImportService.ORGANISATION));
return (StringUtils.equals(string, "* organisation")) ? true : false;
   }
 
Example 30
Source Project: lams   Source File: ImportService.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Organisation parseGroup(HSSFRow row, int rowIndex) {
Organisation org = new Organisation();
String[] args = new String[1];

String name = StringUtils.substring(parseStringCell(row.getCell(ImportService.NAME)), 0, 240);

//validate organisation name
if (StringUtils.isBlank(name)) {
    rowResult.add(messageService.getMessage("error.name.required"));
    hasError = true;
    return null;

} else if (!ValidationUtil.isOrgNameValid(name)) {
    rowResult.add(messageService.getMessage("error.name.invalid.characters"));
    hasError = true;
    return null;
}

org.setName(name);
org.setCode(parseStringCell(row.getCell(ImportService.CODE)));
org.setDescription(parseStringCell(row.getCell(ImportService.DESCRIPTION)));

String orgStateText = parseStringCell(row.getCell(ImportService.ORGANISATION_STATE));
OrganisationState orgState = getOrganisationState(orgStateText);
org.setOrganisationState(orgState);

org.setOrganisationType((OrganisationType) service.findById(OrganisationType.class,
	parentOrg.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.ROOT_TYPE)
		? OrganisationType.COURSE_TYPE
		: OrganisationType.CLASS_TYPE));

org.setParentOrganisation(parentOrg);
org.setCourseAdminCanAddNewUsers(parseBooleanCell(row.getCell(ImportService.ADMIN_ADD_NEW_USERS)));
org.setCourseAdminCanBrowseAllUsers(parseBooleanCell(row.getCell(ImportService.ADMIN_BROWSE_ALL_USERS)));
org.setCourseAdminCanChangeStatusOfCourse(parseBooleanCell(row.getCell(ImportService.ADMIN_CHANGE_STATUS)));

return (hasError ? null : org);
   }