How to create and save Excel file to DAM using java
i trying create 1 excel sheet , save dam.i able create excel in dam, no data there in excel. using following codes 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 = this.getclass().getresourceasstream("/content/dam/company/filefolder/" + filename);
asset asset = manager.createasset("/content/dam/company/filefolder/" + filename, is, "application/vnd.ms-excel", true);
file creating in path "/content/dam/company/filefolder/"
file name "updatedmetadata.xls"
thanks in advance
mahesh narayanan
i found myself. sharing code in future 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);
More discussions in JavaScript
adobe
Comments
Post a Comment