use of org.apache.poi.hssf.usermodel.HSSFCell in project OpenClinica by OpenClinica.
the class SpreadSheetTableRepeating method toHTML.
public String toHTML(int sheetIndex) throws IOException {
StringBuffer buf = new StringBuffer();
HSSFWorkbook wb = new HSSFWorkbook(fs);
int numSheets = wb.getNumberOfSheets();
for (int j = 0; j < numSheets; j++) {
// sheetIndex);
HSSFSheet sheet = wb.getSheetAt(j);
String sheetName = wb.getSheetName(j);
buf.append(sheetName + "<br>");
buf.append("<table border=\"2\"");
buf.append("caption=\"" + wb.getSheetName(sheetIndex) + "\"" + ">");
int numCols = sheet.getPhysicalNumberOfRows();
for (int i = 0; i < numCols; i++) {
buf.append("<tr>");
if (sheet.getRow(i) == null) {
continue;
}
int numCells = sheet.getRow(i).getLastCellNum();
for (int y = 0; y < numCells; y++) {
HSSFCell cell = sheet.getRow(i).getCell((short) y);
int cellType = 0;
if (cell == null) {
cellType = HSSFCell.CELL_TYPE_BLANK;
} else {
cellType = cell.getCellType();
}
switch(cellType) {
case HSSFCell.CELL_TYPE_BLANK:
buf.append("<td> </td>");
break;
case HSSFCell.CELL_TYPE_NUMERIC:
buf.append("<td>" + cell.getNumericCellValue() + "</td>");
break;
case HSSFCell.CELL_TYPE_STRING:
buf.append("<td>" + cell.getStringCellValue() + "</td>");
break;
default:
buf.append("<td></td>");
}
}
buf.append("</tr>");
}
buf.append("</table>");
}
// end of sheet count, added by tbh 5-31
return buf.toString();
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project head by mifos.
the class XlsLoansAccountImporter method getCellDecimalValue.
private BigDecimal getCellDecimalValue(HSSFRow row, XlsLoansImportTemplateConstants currentCell) throws XlsParsingException {
final HSSFCell cell = row.getCell(currentCell.getValue(), HSSFRow.RETURN_BLANK_AS_NULL);
BigDecimal result = null;
if (cell != null) {
switch(cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
HSSFRichTextString richText = cell.getRichStringCellValue();
try {
result = new BigDecimal(richText.getString());
} catch (NumberFormatException ex) {
throw new XlsParsingException(getCellError(XlsMessageConstants.NOT_A_NUMBER, row, currentCell.getValue(), null));
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
double val = cell.getNumericCellValue();
result = new BigDecimal(val);
break;
default:
return null;
}
}
return result;
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project head by mifos.
the class XlsLoansAccountImporter method getCellIntegerValue.
private Integer getCellIntegerValue(HSSFRow row, XlsLoansImportTemplateConstants currentCell) throws XlsParsingException {
final HSSFCell cell = row.getCell(currentCell.getValue(), HSSFRow.RETURN_BLANK_AS_NULL);
Integer result = null;
if (cell != null) {
switch(cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
HSSFRichTextString richText = cell.getRichStringCellValue();
try {
result = new Integer(richText.getString());
} catch (NumberFormatException ex) {
throw new XlsParsingException(getCellError(XlsMessageConstants.NOT_A_NUMBER, row, currentCell.getValue(), null));
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
double val = cell.getNumericCellValue();
result = new Integer((int) val);
break;
default:
return null;
}
}
return result;
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project head by mifos.
the class XlsSavingsAccountImporter method getCellDecimalValue.
private BigDecimal getCellDecimalValue(HSSFRow row, XlsSavingsImportTemplateConstants currentCell) throws XlsParsingException {
final HSSFCell cell = row.getCell(currentCell.getValue(), HSSFRow.RETURN_BLANK_AS_NULL);
BigDecimal result = null;
if (cell != null) {
switch(cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
HSSFRichTextString richText = cell.getRichStringCellValue();
try {
result = new BigDecimal(richText.getString());
} catch (NumberFormatException ex) {
throw new XlsParsingException(getCellError(XlsMessageConstants.NOT_A_NUMBER, row, currentCell.getValue(), null));
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
double val = cell.getNumericCellValue();
result = new BigDecimal(val);
break;
default:
return null;
}
}
return result;
}
use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.
the class SmjXlsReport method reportTable.
// titleTable
/**
* llena los datos del reporte - fill report data
* @param book
* @param data
* @param sheet
* @param fila
*/
public void reportTable(HSSFWorkbook book, LinkedList<ReportTO> data, HSSFSheet sheet, int fila) {
HSSFRow row;
// crea fuente - create font
HSSFFont font = book.createFont();
font.setFontHeightInPoints((short) 10);
font.setFontName(HSSFFont.FONT_ARIAL);
HSSFRichTextString text;
Iterator<ReportTO> itRep = data.iterator();
Boolean newRow = false;
sheet.setColumnWidth((short) 0, (short) (13 * 256));
sheet.setColumnWidth((short) 1, (short) (60 * 256));
for (int i = 2; i < (cols); i++) {
sheet.setColumnWidth((short) i, (short) (15 * 256));
}
//for
// estio celda - cell style
HSSFCellStyle cellStyle = book.createCellStyle();
HSSFCellStyle cellStyleD = book.createCellStyle();
HSSFCellStyle cellStyleN = book.createCellStyle();
while (itRep.hasNext()) {
short col = 0;
ReportTO rpt = itRep.next();
if (!newRow) {
cellStyle = book.createCellStyle();
cellStyleD = book.createCellStyle();
cellStyleN = book.createCellStyle();
}
//if
newRow = false;
if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("T")) {
// Coloca titulo - put title
row = sheet.createRow(fila++);
HSSFFont fontT = book.createFont();
fontT.setFontHeightInPoints((short) 12);
fontT.setFontName(HSSFFont.FONT_ARIAL);
fontT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle cellStyleT = book.createCellStyle();
cellStyleT.setWrapText(true);
cellStyleT.setAlignment(HSSFCellStyle.ALIGN_CENTER);
cellStyleT.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyleT.setFont(fontT);
Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
text = new HSSFRichTextString(rpt.getDescription());
HSSFCell cellT = row.createCell(col);
cellT.setCellStyle(cellStyleT);
cellT.setCellValue(text);
newRow = true;
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("L")) {
// coloca linea en el reporte - Put under line in the report
cellStyle.setWrapText(true);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBottomBorderColor((short) 8);
cellStyleD.setWrapText(true);
cellStyleD.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
cellStyleD.setBottomBorderColor((short) 8);
cellStyleN.setWrapText(true);
cellStyleN.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
cellStyleN.setBottomBorderColor((short) 8);
newRow = true;
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("X")) {
// coloca linea de total - Put total line
cellStyle.setWrapText(true);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
cellStyle.setBottomBorderColor((short) 8);
newRow = true;
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("Z")) {
// coloca linea doble de total - Put total line doble
cellStyle.setWrapText(true);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);
cellStyle.setBottomBorderColor((short) 8);
//--------------
row = sheet.createRow(fila++);
ReportTO rptD = new ReportTO();
putRow(cellStyle, cellStyleD, cellStyleN, sheet, row, fila, rptD);
cellStyle = book.createCellStyle();
newRow = true;
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("D")) {
// coloca liena de descripcion - put description line
cellStyleD.setWrapText(true);
cellStyleD.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
cellStyleD.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
cellStyleD.setBottomBorderColor((short) 8);
newRow = true;
} else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("S")) {
// coloca linea en blanco - put empty line
row = sheet.createRow(fila++);
newRow = true;
} else if (rpt.getTablevel() != null && rpt.getTablevel() > 0) {
// coloca espacios a la izquierda para simular jeraquia - put
// left spaces to simulate hierarchy
row = sheet.createRow(fila++);
String jerarchy = "";
for (int i = 1; i <= rpt.getTablevel(); i++) {
jerarchy = jerarchy + " ";
}
//for
Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
sheet.addMergedRegion(region);
text = new HSSFRichTextString(jerarchy + rpt.getDescription());
HSSFCell cellJ = row.createCell(col);
cellJ.setCellValue(text);
newRow = true;
} else {
row = sheet.createRow(fila++);
putRow(cellStyle, cellStyleD, cellStyleN, sheet, row, fila, rpt);
}
//else
}
// while itData
}
Aggregations