Can u please help me to get the code for writing the given input text files and it should be written to an Excel file.Text file to Excel file is the simplest question of mine.I have give certain codes to get but it not works properly.Below I will copy my written coding.
public boolean createfile(String input,String output,String engine,String from, String to) {
this.input=input;
this.output=output;
this.engine=engine;
this.from=from;
this.to=to;
Excelget write1 =new Excelget();
write1.setInput(input);
write1.setOutput(output);
write1.setEngine(engine);
write1.setFrom(from);
write1.setTo(to);
al.add(write1);
try {
String fpath = "/sdcard/" + "output" + ".xls";
java.io.File file1 = new java.io.File(fpath);
createExcelSheet(file1);
// If file does not exists, then create it
if (!file1.exists()) {
file1.createNewFile();
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
java.io.File file;
WritableWorkbook workbook;
public void createExcelSheet(java.io.File file) {
this.file=file;
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
try {
workbook = Workbook.createWorkbook(file, wbSettings);
createFirstSheet();
//closing cursor
workbook.write();
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
}
void createFirstSheet() {
try {
//Excel sheet name. 0 (number)represents first sheet
WritableSheet sheet = workbook.createSheet("sheet1", 0);
// column and row title
sheet.addCell(new Label(0, 0, "Original text"));
sheet.addCell(new Label(1, 0, "Translated text"));
sheet.addCell(new Label(2, 0, "Engine"));
sheet.addCell(new Label(3, 0, "Translated from"));
sheet.addCell(new Label(4, 0, "Translated to"));
for(Excelget i:al) {
sheet.addCell(new Label(0, 1, i.getInput()));
sheet.addCell(new Label(0, 2, i.getOutput()));
sheet.addCell(new Label(0, 3, i.getEngine()));
sheet.addCell(new Label(0, 4, i.getFrom()));
sheet.addCell(new Label(0, 5, i.getTo()));
}
} catch (Exception e) {
e.printStackTrace();
}
}