You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/06/15 13:48:30 UTC
[Bug 59707] New: Create new line in cell doesn't work with
BufferedReader
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: dev@poi.apache.org
Reporter: rbidet@ribics.fr
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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #7 from rbidet@ribics.fr ---
[...] This create a new line.
If i'm using the same thing but via a BufferedReader, it doesn't create the new
line, that correspond to the ALT+Enter combination key.
Sorry for the 2 comments, i submitted the first too quickly.
Thank for helping.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
--- Comment #10 from Dominik Stadler <do...@gmx.at> ---
The \n is a Java thing which only works in Strings that are embedded in code,
not if you put it into a text-file which you read in via some sort of
Reader/InputStream. The only way to have a newline inserted here is to actually
put a newline into the textfile, so try to make the file look as follows and it
should work:
---- cut here -------
Use
with word wrap on to create a new line
---- cut here -------
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #3 from rbidet@ribics.fr ---
Created attachment 34159
--> https://bz.apache.org/bugzilla/attachment.cgi?id=34159&action=edit
test file
The test file i've used.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
rbidet@ribics.fr changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |REOPENED
Resolution|INVALID |---
--- Comment #4 from rbidet@ribics.fr ---
Hi Dominik,
Sorry for the delay, i was on holidays.
I've attached my test file (toto.txt).
I'm a bit surprised about your last response "I don't think we would be
handling a literal \n as newline anywhere in POI."
It's part of the sample
https://poi.apache.org/spreadsheet/quick-guide.html#NewLinesInCells
Let me know if i can help or need further details.
Rich.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #9 from Mark B <ma...@tiscali.co.uk> ---
I suspect that you will need to escape the backslash character in that case.
Rather than "Use \n with word wrap on to create a new line" your text file will
need to contain "Use \\n with word wrap on to create a new line". Not certain
on this one but I suspect that is the solution to the problem.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #6 from rbidet@ribics.fr ---
Hi Mark,
My testFile is a just a plain text file containing the same string that the
sample.
If i use :
Cell cell = row.createCell(2);
cell.setCellValue("Use \n with word wrap on to create a new line");
=> This create
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #5 from Mark B <ma...@tiscali.co.uk> ---
The \n sequence is an escape sequence that is interpreted to mean a new line
when it - the escape sequence - a[pears in a Java string. The example in the
Quick Guide uses Java to create the sheet/row/cell and populate it. I suspect
this is not what you are doing, rather you are reading from an existing file
and attempting to modify it.
Am I correct in assuming that you have a test file that you have created using
Excel? Further, that this file contains a cell into which you have written the
string? If that is correct, then you never will see a new line. To create a new
line in a cell using Excel itself then you need to press and hold down the Alt
key and then press the enter key.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |WORKSFORME
Status|NEEDINFO |RESOLVED
--- Comment #11 from Dominik Stadler <do...@gmx.at> ---
No update on this discussion for some time, as far as I see this is not a
problem in Apache POI.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |RESOLVED
Resolution|--- |INVALID
--- Comment #2 from Dominik Stadler <do...@gmx.at> ---
No update on the question and I don't think we would be handling a literal \n
as newline anywhere in POI.
If this is still a problem for you then please reopen this bug with some more
information, ideally a self-contained unit-test that shows the problem that you
are facing.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |NEW
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
OS| |All
--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
Can you attach the toto.txt-file?
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 59707] Create new line in cell doesn't work with BufferedReader
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59707
--- Comment #8 from rbidet@ribics.fr ---
(In reply to Mark B from comment #5)
> The \n sequence is an escape sequence that is interpreted to mean a new line
> when it - the escape sequence - a[pears in a Java string. The example in the
> Quick Guide uses Java to create the sheet/row/cell and populate it. I
> suspect this is not what you are doing, rather you are reading from an
> existing file and attempting to modify it.
>
> Am I correct in assuming that you have a test file that you have created
> using Excel? Further, that this file contains a cell into which you have
> written the string? If that is correct, then you never will see a new line.
> To create a new line in a cell using Excel itself then you need to press and
> hold down the Alt key and then press the enter key.
In addition, my test file wasn't created with Excel but via the POI library :
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet(sheetName);
So it's a brand new one, and i'm trying to create a cell (via the POI library),
and to populate this cell with the content of a plain text file.
It works great, except for the lines that contains \n
The cell.setCellValue(fileLine); write the \n instead of creating a new line.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org