I'm working on a requirement to pull .xlsx file from FTP Server & save as .csv file in NFS/ECC al11 folder.
I'm having trouble converting xlsx to csv... can someone help me with the Java code if you already worked on similar requirement. Also help me with standard module to achieve this requirement if any. Thanks in Advance.
I'm using below Java code for the same requirment but its just adding the .csv extension to the file but it's not formatting of the file is wrong.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class CSV_Naming extends AbstractTransformation {
private AbstractTrace trace = null;
private String fileName = "",outputFilename = "";
private String targetDirectory = "";
String dateString1 = "", messageId = "";
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1)
throws StreamTransformationException {
// TODO Auto-generated method stub
try
{
trace = this.getTrace();
trace.addInfo("JAVA Mapping Called");
targetDirectory = (String)arg0.getInputParameters().getString("Directory");
//Create objects for Dynamic configuration to get the input file name
DynamicConfigurationKey KEY_FILENAME =
DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
DynamicConfigurationKey KEY_DIRECTORY =
DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
DynamicConfiguration conf = arg0.getDynamicConfiguration();
fileName=conf.get(KEY_FILENAME);
trace.addWarning("file name is"+fileName);
int index=0;
index=fileName.indexOf(".");
if(index==-1){
outputFilename=fileName+".csv";
}else{
outputFilename=fileName.substring(0, index)+".csv";
}
conf.put(KEY_FILENAME, outputFilename);
conf.put(KEY_DIRECTORY, targetDirectory);
// 5) Copy the input Stream to Output Stream
byte[] b = new byte[arg0.getInputPayload().getInputStream().available()];
arg0.getInputPayload().getInputStream().read(b);
arg1.getOutputPayload().getOutputStream().write(b);
trace.addInfo("End of JAVA Mapping");
}
catch (Exception exception) {
exception.printStackTrace();
}
}
}