Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Excel中导出AEM报告?_Aem - Fatal编程技术网

如何在Excel中导出AEM报告?

如何在Excel中导出AEM报告?,aem,Aem,我想导出excel文件中的AEM报告、页面活动或组件活动报告 AEM中是否有此功能,或者我是否必须为此编写自定义功能?最接近的是CSV选择器,它可以将报告数据转换为CSV,但也有一些限制(分页、过滤器可能会根据报告而忽略) 这不是一个OOTB函数。有一些旧的帖子和博客展示了如何在bpth客户端(使用JS)或服务器端使用CSV编写器完成这项工作 如果您正在编写自定义解决方案(很可能是outcoume),请查看acs commons用户CSV导入/导出实用程序中使用的CSV文本库,它使工作变得非常简

我想导出excel文件中的AEM报告、页面活动或组件活动报告


AEM中是否有此功能,或者我是否必须为此编写自定义功能?

最接近的是CSV选择器,它可以将报告数据转换为CSV,但也有一些限制(分页、过滤器可能会根据报告而忽略)

这不是一个OOTB函数。有一些旧的帖子和博客展示了如何在bpth客户端(使用JS)或服务器端使用CSV编写器完成这项工作

如果您正在编写自定义解决方案(很可能是outcoume),请查看acs commons用户CSV导入/导出实用程序中使用的CSV文本库,它使工作变得非常简单,并且已经是AEM的一部分


希望这有帮助。

您需要编写自己的逻辑 创建一个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格式的报告。

您可以按照此处描述的步骤操作:

  • 选择所需页面以查看组件报告

  • 现在点击下面的URL。它提供JSON输出

  • 将生成的JSON输出复制粘贴到下面的URL,然后单击JSON到excel


  • WriteExcel类仅获取用于填充JTable对象的列表集合,并将数据写入Excel电子表格

    此类使用Java Excel API。使用此API所需的JavaExcelAPI依赖项已在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;
        }
    }
    
    导入java.io.File;
    导入java.io.IOException;
    导入java.util.List;
    导入java.util.Locale;
    导入jxl.CellView;
    导入jxl.工作簿;
    导入jxl.WorkbookSettings;
    导入jxl.format.UnderlineStyle;
    导入jxl.write.Formula;
    导入jxl.write.Label;
    导入jxl.write.Number;
    导入jxl.write.WritableCellFormat;
    导入jxl.write.WritableFont;
    导入jxl.write.WritableSheet;
    导入jxl.write.WritableWorkbook;
    导入jxl.write.WriteException;
    导入jxl.write.biff.rowseceedexception;
    公共类WriteExcel{
    私有可写CellFormat timesBoldUnderline;
    私有可写单元格式时间;
    私有字符串输入文件;
    公共void setOutputFile(字符串输入文件){
    this.inputFile=inputFile;
    }
    public int write(List memberList)抛出IOException,WriteException{
    文件文件=新文件(inputFile);
    WorkbookSettings wbSettings=新建WorkbookSettings();
    设置语言环境(新语言环境(“en”、“en”));
    WritableWorkbook=workbook.createWorkbook(文件,wbSettings);
    工作簿.createSheet(“Comumunity报告”,0);
    WritableSheet excelSheet=workbook.getSheet(0);
    createLabel(excelSheet);
    int size=createContent(excelSheet,成员列表);
    workbook.write();
    workbook.close();
    返回大小;
    }
    私有void createLabel(可写工作表)
    抛出WriteException{
    //让我们创建一个times字体
    WritableFont times10pt=新的WritableFont(WritableFont.TIMES,10);
    //定义单元格格式
    times=新的可写单元格格式(times10pt);
    //让我们自动包装单元格
    times.setWrap(true);
    //创建带有粗体线的字体
    WritableFont times10ptBoldUnderline=新的WritableFont(WritableFont.TIMES,10,WritableFont.BOLD,false,
    花柱(单瓣);
    timesBoldUnderline=新的可写单元格格式(times10ptBoldUnderline);
    //让我们自动包装单元格
    timesBoldUnderline.setWrap(true);
    CellView cv=新的CellView();
    简历格式(次);
    cv.setFormat(timesBoldUnderline);
    cv.setAutosize(真);
    //写几个标题
    添加标题(第0页,第0页,“编号”);
    添加标题(第1页,第0页,“点数”);
    添加标题(第2页,第0页,“名称”);
    添加标题(第3页,第0页,“屏幕名称”);
    }
    private int createContent(WritableSheet sheet,List memberList)引发WriteException,
    rowseceedexception{
    int size=memberList.size();
    //这是我们将从JCR添加数据的地方
    对于(int i=0;i