https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Bug ID: 59707
Summary: Create new line in cell doesn't work with
BufferedReader
Product: POI
Version: 3.15-dev
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
Hi all,
First of all, many thanks for this amazing library.
I'm trying to create a new line in a cell by reading a file.
I've implemented the sample
https://poi.apache.org/spreadsheet/quick-guide.html#NewLinesInCells that works
fine.
I've modified the code in order to read an external file with the same content,
and the \n is written in the file instead of having a new line.
{code}
public static void readTextFile() {
BufferedReader br = null;
;
try {
br = new BufferedReader(new FileReader("C:/tmp/toto.txt"));
String fileLine = "";
String excelFileName = "C:/tmp/Test.xlsx";// name of excel file
String sheetName = "Sheet1";// name of sheet
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(sheetName);
while ((fileLine = br.readLine()) != null) {
System.out.println(fileLine);
Row row = sheet.createRow(2);
Cell cell = row.createCell(2);
cell.setCellValue(fileLine);
// to enable newlines you need set a cell styles with wrap=true
CellStyle cs = wb.createCellStyle();
cs.setWrapText(true);
cell.setCellStyle(cs);
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
// write this workbook to an Outputstream.
wb.write(fileOut);
fileOut.flush();
fileOut.close();
br.close();
} catch (IOException ioe) {
ioe.getMessage();
}
}
{code}
My file contains only :
Use \n with word wrap on to create a new line
I've tried with new XSSFRichTextString(fileLine), but the \n is still present
in the xlsx file.
Do i miss something ? Is it a bug ?
Thank you in advance for your replies and/or correction.
Rich.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]