I managed to set label for my Excel, but I want to set values to cells which is an array and I want to set values with For loop but with this code my for loop doesn't work and label 4 and 5 don't write in my Excel file. how can i set values to cells that those values change in every iteration?
String sdCard = getExternalFilesDir("/").getAbsolutePath();
File directory = new File(sdCard "/MyFolder/");
//create directory if not exist
if(!directory.isDirectory()){
directory.mkdirs();
//Toast.makeText(getApplicationContext(),"dir",Toast.LENGTH_LONG).show();
}
//file path
File file = new File(directory, fileName);
WorkbookSettings wbSettings = new WorkbookSettings();
//wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook;
try {
int a = 1;
workbook = Workbook.createWorkbook(file, wbSettings);
//Toast.makeText(getApplicationContext(),"done4",Toast.LENGTH_LONG).show();
//Excel sheet name. 0 represents first sheet
WritableSheet sheet = workbook.createSheet("Mydata1", 0);
//Toast.makeText(getApplicationContext(),"done3",Toast.LENGTH_LONG).show();
Label label0 = new Label(0,0,"Date");
Label label1 = new Label(1,0,"time");
Label label2 = new Label(2,0,"xCor");
Label label3 = new Label(3,0,"score");
Label label7 = new Label(2,1,xCor[2]);
try {
sheet.addCell(label0);
sheet.addCell(label1);
sheet.addCell(label2);
sheet.addCell(label3);
for(int i3 = 1; i3==j 1 ; i3 ) {
String text = xCor[i3];
sheet.getWritableCell(text);
Label label4 = new Label(2,i3,text);
Label label5 = new Label(1,i3,text);
sheet.addCell(label4);
sheet.addCell(label5);
}
sheet.addCell(label7);
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
workbook.write();
try {
workbook.close();
} catch (WriteException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
CodePudding user response:
It is difficult to tell ...because variable a
is unused, j
and xCor
are being defined nowhere.
But one cannot have i3 == j 1
as the run condition for a for
loop, because the condition will never be true and therefore the execution will never enter that control flow statement (dead code).
Most commonly, one may want to compare the loop index with the smaller or equal operator:
for (int i=1; i <= j; i ) { ... }
Logging to console can greatly help to determine what a loop actually does, for example:
Log.d(LOG_TAG, "i3 = " i3 );
Also see the JavaDocs ...assuming that this is jxl.write
.
Alike this you might eventually learn how it works.