我正在尝试创建一个 excel 表并将其保存到 DAM 中。我能够在 DAM 中创建 excel,但该 excel 中没有数据。我正在使用以下代码来创建它。
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);
文件正在此路径“/content/dam/company/fileFolder/”中创建文件名为“updatedMetadata.xls”
在此先感谢 Mahesh Narayanan