use of org.apache.poi.hssf.usermodel.HSSFRow in project ddf by codice.
the class RrdMetricsRetrieverTest method verifyWorksheet.
private void verifyWorksheet(HSSFSheet sheet, String metricName, int expectedNumberOfDataRows, boolean hasTotalCount) {
// 3 = title + blank row + column headers
int expectedTotalRows = 3 + expectedNumberOfDataRows;
if (hasTotalCount) {
expectedTotalRows += 2;
}
assertThat(sheet.getPhysicalNumberOfRows(), equalTo(expectedTotalRows));
// first row should have title in first cell
HSSFRow row = sheet.getRow(0);
assertThat(row, not(nullValue()));
assertThat(row.getCell(0).getStringCellValue(), startsWith(metricName + " for"));
// third row should have column headers in first and second cells
row = sheet.getRow(2);
assertThat(row.getCell(0).getStringCellValue(), equalTo("Timestamp"));
assertThat(row.getCell(1).getStringCellValue(), equalTo("Value"));
// verify rows with the sample data, i.e., timestamps and values
int endRow = 3 + expectedNumberOfDataRows;
for (int i = 3; i < endRow; i++) {
row = sheet.getRow(i);
assertThat(row.getCell(0).getStringCellValue(), not(nullValue()));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
}
row = sheet.getRow(sheet.getLastRowNum());
if (hasTotalCount) {
assertThat(row.getCell(0).getStringCellValue(), startsWith("Total Count:"));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
} else {
assertThat(row.getCell(0).getStringCellValue(), not(startsWith("Total Count:")));
}
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsDataAsXls.
@Test
public void testGetMetricsDataAsXls() throws Exception {
// Create RRD file that Metrics Endpoint will detect
// 15 minutes in seconds
int dateOffset = 900;
createRrdFile(dateOffset);
UriInfo uriInfo = createUriInfo();
// Get the metrics data from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsData("uptime", "xls", null, null, Integer.toString(dateOffset), "my label", "my title", uriInfo);
cleanupRrd();
InputStream xls = (InputStream) response.getEntity();
assertThat(xls, not(nullValue()));
HSSFWorkbook wb = new HSSFWorkbook(xls);
assertThat(wb.getNumberOfSheets(), equalTo(1));
HSSFSheet sheet = wb.getSheet("Uptime");
assertThat(sheet, not(nullValue()));
// Expect 7 rows: title + blank + column headers + 2 rows of samples + blank +
// totalQueryCount
assertThat(sheet.getPhysicalNumberOfRows(), equalTo(7));
// first row should have title in first cell
HSSFRow row = sheet.getRow(0);
assertThat(row, not(nullValue()));
assertThat(row.getCell(0).getStringCellValue(), startsWith("Uptime for"));
// third row should have column headers in first and second cells
row = sheet.getRow(2);
assertThat(row.getCell(0).getStringCellValue(), equalTo("Timestamp"));
assertThat(row.getCell(1).getStringCellValue(), equalTo("Value"));
// should have 2 rows of samples' data
row = sheet.getRow(3);
assertThat(row.getCell(0).getStringCellValue(), not(nullValue()));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
row = sheet.getRow(4);
assertThat(row.getCell(0).getStringCellValue(), not(nullValue()));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
// last row should have totalQueryCount in first cell
row = sheet.getRow(sheet.getLastRowNum());
assertThat(row.getCell(0).getStringCellValue(), startsWith("Total Count:"));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project processdash by dtuma.
the class WBSExcelWriter method writeDataForNodes.
private int writeDataForNodes(HSSFSheet sheet, int rowNum, WBSNode node, TableColumnModel columns) {
HSSFRow row = sheet.createRow(rowNum);
writeCellForNodeName(node, row);
writeCellsForNodeData(row, node, columns);
WBSNode[] children = wbs.getChildren(node);
if (children.length == 0)
return rowNum;
int childRowPos = rowNum;
for (WBSNode child : children) {
if (!child.isHidden())
childRowPos = writeDataForNodes(sheet, childRowPos + 1, child, columns);
}
sheet.groupRow(rowNum + 1, childRowPos);
if (!node.isExpanded())
sheet.setRowGroupCollapsed(rowNum + 1, true);
return childRowPos;
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project processdash by dtuma.
the class WBSExcelWriter method createHeaderRow.
private void createHeaderRow(HSSFSheet sheet, TableColumnModel columns) {
HSSFRow row = sheet.createRow(0);
StyleKey style = new StyleKey();
style.bold = true;
for (int i = 0; i < columns.getColumnCount(); i++) {
TableColumn col = columns.getColumn(i);
String columnName = data.getColumnName(col.getModelIndex());
HSSFCell cell = row.createCell(s(i + 1));
cell.setCellValue(new HSSFRichTextString(columnName));
styleCache.applyStyle(cell, style);
}
}
use of org.apache.poi.hssf.usermodel.HSSFRow in project portal by ixinportal.
the class ExcelFileGenerator method createWorkbook.
/**
* 创建HSSFWorkbook对象
*
* @return HSSFWorkbook
*/
public HSSFWorkbook createWorkbook() {
// 创建workbook对象
workBook = new HSSFWorkbook();
int rows = fieldData.size();
int sheetNum = 1;
for (int i = 1; i <= sheetNum; i++) {
// 使用wookbook对象创建sheet对象
HSSFSheet sheet = workBook.createSheet("Page " + i);
// 使用HSSFSheet对象创建row,row的下标从0开始
HSSFRow headRow = sheet.createRow(0);
for (int j = 0; j < fieldName.size(); j++) {
// 循环excel的标题
// 使用HSSFRow创建cell,cell的下标从0开始
HSSFCell cell = headRow.createCell(j);
// 添加样式
// 设置每一列的宽度
sheet.setColumnWidth(j, 6000);
// 创建样式
HSSFCellStyle cellStyle = workBook.createCellStyle();
// 设置字体
// 创建字体对象
HSSFFont font = workBook.createFont();
// 将字体变为粗体
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
// 将字体颜色变红色
short color = HSSFColor.RED.index;
font.setColor(color);
// 设置之后的字体
cellStyle.setFont(font);
// 添加样式
// 设置单元格的类型
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
if (fieldName.get(j) != null) {
cell.setCellStyle(cellStyle);
// 赋值
cell.setCellValue((String) fieldName.get(j));
} else {
cell.setCellStyle(cellStyle);
cell.setCellValue("-");
}
}
for (int k = 0; k < rows; k++) {
// 分页显示数据
// 使用HSSFSheet对象创建row,row的下标从0开始
HSSFRow row = sheet.createRow((k + 1));
// 将数据内容放入excel单元格
// 循环数据集
ArrayList rowList = (ArrayList) fieldData.get((i - 1) + k);
for (int n = 0; n < rowList.size(); n++) {
// 使用HSSFRow创建cell,cell的下标从0开始
HSSFCell cell = row.createCell(n);
if (rowList.get(n) != null) {
cell.setCellValue((String) rowList.get(n).toString());
} else {
cell.setCellValue("");
}
}
}
}
return workBook;
}
Aggregations