Password Protected XLSX

This example demonstrates how to set up a password upon rendering a XLSX RML template.

Notes:

  • This feature is only available for “XLSX” output
  • This feature is only available from Ambience 4.6.3 onwards

1. Using Ambience Designer

Setting Up Password upon XLSX Rendering

  1. Over at Render Wizard, choose the “XLSX” output.
  2. Click the “Next” button.
  3. Enter desired password in the “Password” field.
  4. Click “Finish”
  5. A password prompt will be shown as below
    image

2. Using ERSClient for Dynamic Passwords

Setting Up Password upon XLSX Rendering
This example is using Java Language

  1. Create a new java class (for e.g. “ERSClient.java”) on your preferred IDE.

  2. Configure your java build path with the following .jar files:
    image

  3. Copy in the following line of codes into the main method of ERSClient.java class
    Do change the properties/parameters that are emphasized in the [ ] brackets accordingly

ERSClient c = new ERSClient("[host]", [port], "[domain]", "[username]", "[password]");
	    try {
	    	System.out.println("Connecting...");
	    	c.connect();
	    	
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          Properties renderprops = new Properties();
          renderprops.put("elx.rd.Password", "[desired-password]");
         		
	      IJobInfo jobInfo = c.renderReport("[path-to-your-RML-template]", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", baos, renderprops);
	      byte[] bytes = baos.toByteArray();
	      File output = new File("tmp/output.xlsx");
	      output.getParentFile().mkdirs();
	      Files.copy(new ByteArrayInputStream(bytes),output.toPath(),StandardCopyOption.REPLACE_EXISTING);
	      System.out.println("Report logged at "+jobInfo.getString(IJobInfo.LOG_FILE) +" with " + jobInfo.getLong(IJobInfo.PAGE_COUNT) + " pages rendered to "+jobInfo.getString(IJobInfo.MIME_TYPE));
	      System.out.println("Rendering results : "+jobInfo.toString());
	    }
	    finally {
	      c.close();
	    }
  1. Save & Run ERSClient.java

  2. The rendered output, “output.xlsx” will be in your Java project /tmp directory.
    image

  3. A password prompt will be shown when attempting to view open the file.
    image