How to set values in cell to write in Android Studio
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();
}
from Recent Questions - Stack Overflow https://ift.tt/39NrYJz
https://ift.tt/eA8V8J
Comments
Post a Comment