我想在Excel文件中导出AEM报告,页面活动或组件活动报告。
此功能在AEM中是否可用,还是我必须为此编写自定义?
答案 0 :(得分:4)
您将获得的最接近的是一个CSV选择器,可以将报告数据转换为CSV,但即使这样也有限制(分页,过滤器可能会被忽略,具体取决于报告)。
这,AFAIK,不是OOTB功能。有一些旧的帖子和博客,以显示如何在bpth客户端(使用JS)或服务器端使用CSV编写器完成此操作。
如果您要编写自定义解决方案(很可能是外部解决方案)的路线,请查看acs-commons用户CSV导入/导出实用程序中使用的CSV文本库,这使得工作非常简单,已经是AEM的一部分。
希望这有帮助。
答案 1 :(得分:3)
WriteExcel 类只需获取用于填充 JTable 对象的List集合,并将数据写入Excel电子表格。
此类使用 Java Excel API 。使用此API所需的Java Excel API依赖关系已在POM依赖关系部分中。
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.UnderlineStyle;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class WriteExcel {
private WritableCellFormat timesBoldUnderline;
private WritableCellFormat times;
private String inputFile;
public void setOutputFile(String inputFile) {
this.inputFile = inputFile;
}
public int write( List<members> memberList) throws IOException, WriteException {
File file = new File(inputFile);
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
workbook.createSheet("Comumunity Report", 0);
WritableSheet excelSheet = workbook.getSheet(0);
createLabel(excelSheet) ;
int size = createContent(excelSheet, memberList);
workbook.write();
workbook.close();
return size ;
}
private void createLabel(WritableSheet sheet)
throws WriteException {
// Lets create a times font
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
// Define the cell format
times = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
times.setWrap(true);
// create create a bold font with unterlines
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false,
UnderlineStyle.SINGLE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
// Lets automatically wrap the cells
timesBoldUnderline.setWrap(true);
CellView cv = new CellView();
cv.setFormat(times);
cv.setFormat(timesBoldUnderline);
cv.setAutosize(true);
// Write a few headers
addCaption(sheet, 0, 0, "Number");
addCaption(sheet, 1, 0, "Points");
addCaption(sheet, 2, 0, "Name");
addCaption(sheet, 3, 0, "Screen Name");
}
private int createContent(WritableSheet sheet, List<members> memberList) throws WriteException,
RowsExceededException {
int size = memberList.size() ;
// This is where we will add Data from the JCR
for (int i = 0; i < size; i++) {
members mem = (members)memberList.get(i) ;
String number = mem.getNum();
String points = mem.getScore();
String name = mem.getName();
String display = mem.getDisplay();
// First column
addLabel(sheet, 0, i+2, number);
// Second column
addLabel(sheet, 1, i+2, points);
// Second column
addLabel(sheet, 2, i+2,name);
// Second column
addLabel(sheet, 3, i+2, display);
}
return size;
}
private void addCaption(WritableSheet sheet, int column, int row, String s)
throws RowsExceededException, WriteException {
Label label;
label = new Label(column, row, s, timesBoldUnderline);
sheet.addCell(label);
}
private void addNumber(WritableSheet sheet, int column, int row,
Integer integer) throws WriteException, RowsExceededException {
Number number;
number = new Number(column, row, integer, times);
sheet.addCell(number);
}
private void addLabel(WritableSheet sheet, int column, int row, String s)
throws WriteException, RowsExceededException {
Label label;
label = new Label(column, row, s, times);
sheet.addCell(label);
}
public int exportExcel( List<members> memberList)
{
try
{
setOutputFile("JCRMembers.xls");
int recs = write( memberList);
return recs ;
}
catch(Exception e)
{
e.printStackTrace();
}
return -1;
}
}
答案 2 :(得分:2)
您可以按照此处描述的步骤操作:Adobe Forums
现在点击以下网址。它为您提供JSON输出。 http://localhost:4502/etc/reports/compreport/jcr:content/report.data.json
将生成的JSON输出复制粘贴到以下网址,然后点击JSON to excel http://www.convertcsv.com/json-to-csv.htm
答案 3 :(得分:0)
你需要编写自己的逻辑 创建一个servlet, 用数据构造表 在响应对象中添加以下行
response.setContentType("text/csv");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=\"" + reportName + ".csv\"");
Cookie cookie = new Cookie("fileDownload", "true");
cookie.setMaxAge(-1);
cookie.setPath("/");
response.addCookie(cookie);
点击按钮后,您将获得Excel格式的报告。