You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Srikanth Vattikonda <su...@gmail.com> on 2014/01/07 05:21:57 UTC

RE: Excel XSSFRichString new line not applied in cell

Hi,
    I am not able to find new lines in the generated excel sheet with the
below code

XSSFFont font1 = workbook.createFont();
font1.setBold(false);
font1.setColor(IndexedColors.BLACK.getIndex());
font1.setFontName("Arial");
font1.setFontHeight(8);
XSSFFont font2 = workbook.createFont();
font2.setBold(true);
font2.setColor(IndexedColors.BLACK.getIndex());
font2.setFontName("Arial");
font2.setFontHeight(11);

XSSFCellStyle cellStyle= workbook.createCellStyle();
cellStyle.setFillForegroundColor(new XSSFColor(new Color(255, 255, 255)));
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setWrapText(true);       // Please note wrap text was enabled
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setVerticalAlignment(VerticalAlignment.TOP);

Cell cell = row.createCell(0);
cell.setCellStyle(cellStyle);

XSSFRichTextString text = new XSSFRichTextString();
text.append("Test", font1);
text.append("\n new line", font2);
// -- Even tried with text.append(System.getProperty("line.separator"),
font2);

cell.setCellValue(text);

                                              Can any one please help me
out on how to get new lines in the cells in this scenario.

Thanks in advance

Regards,
SV

Re: Excel XSSFRichString new line not applied in cell

Posted by Srikanth Vattikonda <su...@gmail.com>.
Hey Ryo,
              Thank you very much. Currently I am using POI 3.7 but
upgrading to 3.9 resolved my issue, I think the preserve spaces
functionality too was missed in 3.7 while appending the text to rich
string.

Thanks again!

Regards,
SV


On Tue, Jan 7, 2014 at 11:14 AM, 山本 亮 <ry...@yjk.co.jp> wrote:

> I use POI 3.9.
> Your code works fine for me.
>
> What version of POI are you using?
>
> Ryo Yamamoto
> -----Original Message-----
> From: Srikanth Vattikonda [mailto:sunny8875@gmail.com]
> Sent: Tuesday, January 07, 2014 1:22 PM
> To: user@poi.apache.org
> Subject: RE: Excel XSSFRichString new line not applied in cell
>
> Hi,
>     I am not able to find new lines in the generated excel sheet with the
> below code
>
> XSSFFont font1 = workbook.createFont();
> font1.setBold(false);
> font1.setColor(IndexedColors.BLACK.getIndex());
> font1.setFontName("Arial");
> font1.setFontHeight(8);
> XSSFFont font2 = workbook.createFont();
> font2.setBold(true);
> font2.setColor(IndexedColors.BLACK.getIndex());
> font2.setFontName("Arial");
> font2.setFontHeight(11);
>
> XSSFCellStyle cellStyle= workbook.createCellStyle();
> cellStyle.setFillForegroundColor(new XSSFColor(new Color(255, 255, 255)));
> cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
> cellStyle.setWrapText(true);       // Please note wrap text was enabled
> cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
> cellStyle.setBorderBottom(BorderStyle.THIN);
> cellStyle.setBorderRight(BorderStyle.THIN);
> cellStyle.setBorderTop(BorderStyle.THIN);
> cellStyle.setBorderLeft(BorderStyle.THIN);
> cellStyle.setVerticalAlignment(VerticalAlignment.TOP);
>
> Cell cell = row.createCell(0);
> cell.setCellStyle(cellStyle);
>
> XSSFRichTextString text = new XSSFRichTextString(); text.append("Test",
> font1); text.append("\n new line", font2); // -- Even tried with
> text.append(System.getProperty("line.separator"),
> font2);
>
> cell.setCellValue(text);
>
>                                               Can any one please help me
> out on how to get new lines in the cells in this scenario.
>
> Thanks in advance
>
> Regards,
> SV
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

RE: Excel XSSFRichString new line not applied in cell

Posted by 山本 亮 <ry...@yjk.co.jp>.
I use POI 3.9.
Your code works fine for me.

What version of POI are you using?

Ryo Yamamoto
-----Original Message-----
From: Srikanth Vattikonda [mailto:sunny8875@gmail.com] 
Sent: Tuesday, January 07, 2014 1:22 PM
To: user@poi.apache.org
Subject: RE: Excel XSSFRichString new line not applied in cell

Hi,
    I am not able to find new lines in the generated excel sheet with the below code

XSSFFont font1 = workbook.createFont();
font1.setBold(false);
font1.setColor(IndexedColors.BLACK.getIndex());
font1.setFontName("Arial");
font1.setFontHeight(8);
XSSFFont font2 = workbook.createFont();
font2.setBold(true);
font2.setColor(IndexedColors.BLACK.getIndex());
font2.setFontName("Arial");
font2.setFontHeight(11);

XSSFCellStyle cellStyle= workbook.createCellStyle(); cellStyle.setFillForegroundColor(new XSSFColor(new Color(255, 255, 255))); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setWrapText(true);       // Please note wrap text was enabled
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setVerticalAlignment(VerticalAlignment.TOP);

Cell cell = row.createCell(0);
cell.setCellStyle(cellStyle);

XSSFRichTextString text = new XSSFRichTextString(); text.append("Test", font1); text.append("\n new line", font2); // -- Even tried with text.append(System.getProperty("line.separator"),
font2);

cell.setCellValue(text);

                                              Can any one please help me out on how to get new lines in the cells in this scenario.

Thanks in advance

Regards,
SV

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


RE: Excel XSSFRichString new line not applied in cell

Posted by "山本 亮 (SE&S)" <ry...@se-s.co.jp>.
I use POI 3.9.
Your code works fine for me.

What version of POI are you using?

Ryo Yamamoto
-----Original Message-----
From: Srikanth Vattikonda [mailto:sunny8875@gmail.com] 
Sent: Tuesday, January 07, 2014 1:22 PM
To: user@poi.apache.org
Subject: RE: Excel XSSFRichString new line not applied in cell

Hi,
    I am not able to find new lines in the generated excel sheet with the below code

XSSFFont font1 = workbook.createFont();
font1.setBold(false);
font1.setColor(IndexedColors.BLACK.getIndex());
font1.setFontName("Arial");
font1.setFontHeight(8);
XSSFFont font2 = workbook.createFont();
font2.setBold(true);
font2.setColor(IndexedColors.BLACK.getIndex());
font2.setFontName("Arial");
font2.setFontHeight(11);

XSSFCellStyle cellStyle= workbook.createCellStyle(); cellStyle.setFillForegroundColor(new XSSFColor(new Color(255, 255, 255))); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setWrapText(true);       // Please note wrap text was enabled
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setVerticalAlignment(VerticalAlignment.TOP);

Cell cell = row.createCell(0);
cell.setCellStyle(cellStyle);

XSSFRichTextString text = new XSSFRichTextString(); text.append("Test", font1); text.append("\n new line", font2); // -- Even tried with text.append(System.getProperty("line.separator"),
font2);

cell.setCellValue(text);

                                              Can any one please help me out on how to get new lines in the cells in this scenario.

Thanks in advance

Regards,
SV

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org