use of org.apache.poi.hssf.usermodel.HSSFSheet in project ddf by codice.
the class RrdMetricsRetrieverTest method testMetricsXlsReportSummary.
@Test
public void testMetricsXlsReportSummary() throws Exception {
String metricName = "queryCount_Gauge";
long endTime = new DateTime(DateTimeZone.UTC).getMillis();
List<String> metricNames = new ArrayList<String>();
metricNames.add(metricName);
for (RrdMetricsRetriever.SUMMARY_INTERVALS interval : RrdMetricsRetriever.SUMMARY_INTERVALS.values()) {
long startTime = 0L;
switch(interval) {
case minute:
startTime = new DateTime(DateTimeZone.UTC).minusHours(1).getMillis();
break;
case hour:
startTime = new DateTime(DateTimeZone.UTC).minusDays(1).getMillis();
break;
case day:
startTime = new DateTime(DateTimeZone.UTC).minusWeeks(1).getMillis();
break;
case week:
startTime = new DateTime(DateTimeZone.UTC).minusMonths(1).getMillis();
break;
case month:
startTime = new DateTime(DateTimeZone.UTC).minusYears(1).getMillis();
break;
}
int sampleSize = (int) ((endTime - startTime) / (RRD_STEP * 1000));
new RrdFileBuilder().rrdFileName(TEST_DIR + metricName + RRD_FILE_EXTENSION).dsType(DsType.GAUGE).numSamples(sampleSize).numRows(sampleSize).startTime(startTime).build();
MetricsRetriever metricsRetriever = new RrdMetricsRetriever();
OutputStream os = metricsRetriever.createXlsReport(metricNames, TEST_DIR, startTime, endTime, interval.toString());
InputStream xls = new ByteArrayInputStream(((ByteArrayOutputStream) os).toByteArray());
assertThat(xls, not(nullValue()));
HSSFWorkbook wb = new HSSFWorkbook(xls);
assertThat(wb.getNumberOfSheets(), equalTo(1));
HSSFSheet sheet = wb.getSheetAt(0);
assertThat(sheet, not(nullValue()));
}
}
use of org.apache.poi.hssf.usermodel.HSSFSheet 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.HSSFSheet in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsReportAsXls.
@Test
public void testGetMetricsReportAsXls() throws Exception {
// Create RRD file that Metrics Endpoint will detect
// 15 minutes in seconds
int dateOffset = 900;
createRrdFile(dateOffset, "uptime");
UriInfo uriInfo = createUriInfo();
// Get the metrics data from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsReport("xls", null, null, Integer.toString(dateOffset), "minute", uriInfo);
cleanupRrd();
MultivaluedMap<String, Object> headers = response.getHeaders();
assertTrue(headers.getFirst("Content-Disposition").toString().contains("attachment; filename="));
InputStream is = (InputStream) response.getEntity();
assertThat(is, not(nullValue()));
HSSFWorkbook wb = new HSSFWorkbook(is);
assertThat(wb.getNumberOfSheets(), equalTo(1));
HSSFSheet sheet = wb.getSheetAt(0);
assertThat(sheet, not(nullValue()));
}
use of org.apache.poi.hssf.usermodel.HSSFSheet in project processdash by dtuma.
the class WBSExcelWriter method addData.
public void addData(String tabName, TableColumnModel columns) {
String safeTabName = cleanupTabName(tabName);
HSSFSheet sheet = xls.createSheet(safeTabName);
// WORKAROUND, for POI bug
// ------ http://issues.apache.org/bugzilla/show_bug.cgi?id=30714
// We should have been able to use the next line...
// sheet.setRowSumsBelow(false);
sheet.setAlternativeExpression(false);
createHeaderRow(sheet, columns);
writeDataForNodes(sheet, 1, wbs.getRoot(), columns);
autoSizeColumns(sheet, columns);
sheet.createFreezePane(1, 1);
}
use of org.apache.poi.hssf.usermodel.HSSFSheet 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