I have a program where I get a string from a text area and then I convert it to an array, then I read this array and then write it to an excel, the writing is working but it doesn't consider the tab spaces. My code is
String getTextArea_1 = textArea_1.getText();
String userHomeFolder = System.getProperty("user.home");
File excelFile = new File(userHomeFolder, "RESULT.xls");
try {
//create .xls and create a worksheet.
FileOutputStream fos = new FileOutputStream(excelFile);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet worksheet = workbook.createSheet("My Work Sheet");
//Create ROW-1 ((row line number in the excel))
HSSFRow row1;
//Create COL-A from ROW-1 and set data
HSSFCell cellA1;
int rowLines = 0;
int colLine = 0;
String[] strings = getTextArea_1.split("\n");
for(String b : strings) {
rowLines ++;
row1 = worksheet.createRow(rowLines -1);
cellA1 = row1.createCell(colLine);
cellA1.setCellValue(b);
colLine = colLine - 1;
colLine ++;
//System.out.println(b);
//colLine ++;
//System.out.println(rowLines);
}
//Save the workbook in .xls file
workbook.write(fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
the result shown is like this image
but I need it to be like the below, as if I copy it from my text area and paste it to the excel sheet this is the result I get:
After using the suggestion of Lancef, the result is only under one cell column, how to make make it under one row?!
1746
C4A
13D06MK
GREECE
2012-07-04
2015-07-03
2012-07-04
2015-07-03
"Yes"
I tried to play with rowLines and colLine but it doesn't work for me, I always get it as
1746
C4A
13D06MK
GREECE
2012-07-04
2015-07-03
2012-07-04
2015-07-03
"Yes"