HSSFWorkbook wb = new HSSFWorkbook(input);
HSSFSheet sheet = wb.getSheetAt(0);
// Open the EDD.xml output file
String tmpEDDfilename = rs.getWorkingdirectory()+tmpEDD;
XMLPrinter xout = new XMLPrinter(new FileOutputStream(tmpEDDfilename));
// Write out a header in the EDD xml file.
xout.opentag("edd_header");
xout.printdata("edd_create_stamp",
new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z").format(new Date())
);
xout.printdata("Excel_File_Name",excelFileName);
xout.closetag();
xout.opentag("edd");
// Get the indexes of the columns we need to write out the XML for this EDD.
int rows = sheet.getLastRowNum();
int entityIndex = findvalue("entity",sheet,0);
int attributeIndex = findvalue("attribute",sheet,0);
int typeIndex = findvalue("type",sheet,0);
int subtypeIndex = findvalue("subtype",sheet,0);
int defaultIndex = findvalue("defaultvalue",sheet,0);
int inputIndex = findvalue("input",sheet,0);
int accessIndex = findvalue("access",sheet,0);
int commentIndex = findvalue("comment",sheet,0); // optional
int sourceIndex = findvalue("source",sheet,0); // optional
// Some columns we just have to have. Make sure we have them here.
if(entityIndex <0 || attributeIndex < 0 || typeIndex < 0 || defaultIndex < 0 || accessIndex < 0 || inputIndex <0 ){
String err = " Couldn't find the following column header(s): "+
(entityIndex<0?" entity":"")+
(attributeIndex<0?" attribute":"")+
(typeIndex<0?" type":"")+
(defaultIndex<0?" default value":"")+
(accessIndex<0?" access":"")+
(inputIndex<0?" input":"");
throw new Exception("This EDD may not be valid, as we didn't find the proper column headers\n"+err);
}
// Go through each row, writing out each entry to the XML.
for(int row = 1; row <=rows; row++){
String entityname = getCellValue(sheet,row,entityIndex); // Skip all the rows that have no Entity
if(entityname.length()>0){
String src = sourceIndex>=0 ? getCellValue(sheet,row,sourceIndex):"";
String comment = commentIndex>=0 ? getCellValue(sheet,row,commentIndex):"";
xout.opentag("entry");
xout.opentag("entity",
"entityname" , entityname,
"attribute" , getCellValue(sheet,row,attributeIndex),
"type" , getCellValue(sheet,row,typeIndex),
"subtype" , getCellValue(sheet,row,subtypeIndex),
"default" , getCellValue(sheet,row,defaultIndex),
"access" , getCellValue(sheet,row,accessIndex),
"input" , getCellValue(sheet,row,inputIndex),
"comment" , getCellValue(sheet,row,commentIndex)
);
xout.closetag();
if(comment.length()>0)xout.printdata("comment",getCellValue(sheet,row,commentIndex));
if(src .length()>0 )xout.printdata("source", getCellValue(sheet,row,sourceIndex));
xout.closetag();
}
}
xout.closetag();
xout.close();
convertEDD(ef,rs, tmpEDDfilename);
}