2 Replies Latest reply on Jul 27, 2016 2:39 AM by try67

    How to create and save Excel file to DAM using java

    MaheshNarayanan

      I am trying to create one excel sheet and save it into DAM.I am able to create excel in DAM, but no data is there in that excel. I am using following codes to create it.

       

      String filename = "updatedMetadata.xls";

          FileOutputStream fos = new FileOutputStream(filename);

          WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));

          WritableSheet writableSheet = workbook.createSheet("Updated Metadata", 0);

          Label label = null;

          label = new Label(0, 0, "Header1");

          writableSheet.addCell(label);

          label = new Label(0, 1, "Header2");

          writableSheet.addCell(label);

          label = new Label(0, 2, "Header3");

          writableSheet.addCell(label);

          label = new Label(0, 3, "Header4");

          writableSheet.addCell(label);

          label = new Label(0, 4, "Header5");

          writableSheet.addCell(label);

          label = new Label(0, 5, "Header6");

          writableSheet.addCell(label);

          label = new Label(0, 6, "Header7");

          writableSheet.addCell(label);

          label = new Label(0, 7, "Header8");

          writableSheet.addCell(label);

          label = new Label(1, 0, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 1, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 2, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 3, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 4, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 5, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 6, "col val");

          writableSheet.addCell(label);

          label = new Label(1, 7, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 0, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 1, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 2, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 3, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 4, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 5, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 6, "col val");

          writableSheet.addCell(label);

          label = new Label(2, 7, "col val");

          writableSheet.addCell(label);

          workbook.write();

          workbook.close();

          ResourceResolver resourceResolver = request.getResourceResolver();

          AssetManager manager = resourceResolver.adaptTo(AssetManager.class);

          InputStream is = this.getClass().getResourceAsStream("/content/dam/company/fileFolder/" + filename);

          Asset asset = manager.createAsset("/content/dam/company/fileFolder/" + filename, is, "application/vnd.ms-excel", true);

       

      File is creating in this Path "/content/dam/company/fileFolder/"

      File name is "updatedMetadata.xls"

       

       

      Thanks in advance

      Mahesh Narayanan

        • 1. Re: How to create and save Excel file to DAM using java
          MaheshNarayanan Level 1

          I found it myself. I am sharing the code so that in future someone else can use it.

           

          String filename = "updatedMetadata.xls";

            File excelFile = new File(filename);

            WritableWorkbook workbook = Workbook.createWorkbook(excelFile);

            WritableSheet writableSheet = workbook.createSheet("Updated Metadata", 0);

           

              Label label = null;

              label = new Label(0, 0, "Header1");

              writableSheet.addCell(label);

              label = new Label(0, 1, "Header2");

              writableSheet.addCell(label);

              label = new Label(0, 2, "Header3");

              writableSheet.addCell(label);

              label = new Label(0, 3, "Header4");

              writableSheet.addCell(label);

              label = new Label(0, 4, "Header5");

              writableSheet.addCell(label);

              label = new Label(0, 5, "Header6");

              writableSheet.addCell(label);

              label = new Label(0, 6, "Header7");

              writableSheet.addCell(label);

              label = new Label(0, 7, "Header8");

              writableSheet.addCell(label);

              label = new Label(1, 0, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 1, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 2, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 3, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 4, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 5, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 6, "col val");

              writableSheet.addCell(label);

              label = new Label(1, 7, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 0, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 1, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 2, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 3, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 4, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 5, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 6, "col val");

              writableSheet.addCell(label);

              label = new Label(2, 7, "col val");

              writableSheet.addCell(label);

              workbook.write();

              workbook.close();

              ResourceResolver resourceResolver = request.getResourceResolver();

              AssetManager manager = resourceResolver.adaptTo(AssetManager.class);

              InputStream stream = new FileInputStream(excelFile);

              Asset asset = manager.createAsset("/content/dam/company/fileFolder/" + filename, is, "application/vnd.ms-excel", true);

          • 2. Re: How to create and save Excel file to DAM using java
            try67 MVP & Adobe Community Professional

            Why did you post all of this to the Adobe forums? This has nothing to do with any Adobe product, as far as I can see.