2017-12-31 48 views
0

저는 Apache POI 3.16을 사용하여 Excel 파일을 만듭니다. 나는 LINEBREAK을 가지고 특정 셀 내부의 데이터를 설정하려면 : 나는 파일을 열 때셀 데이터로 줄 바꿈을 삽입하는 방법은 무엇입니까?

rowConsommationEtRealisation.createCell(0).setCellValue("Consommation (crédits)\r\nRéalisation (produits)"); 

다음 셀의 값이 LINEBREAK이 없습니다! 그래서 linebreak를 만드는 방법?

답변

1

이 시도 : here

Row row = sheet.createRow(2); 
Cell cell = row.createCell(2); 
cell.setCellValue("Use \n with word wrap on to create a new line"); 

//to enable newlines you need set a cell styles with wrap=true 
CellStyle cs = wb.createCellStyle(); 
cs.setWrapText(true); 
cell.setCellStyle(cs); 
2

이미 줄 바꿈이 있지만 셀에 표시되지 않습니다. 랩 텍스트 속성이 셀에 설정된 셀 스타일을 설정해야합니다.

예 :

import org.apache.poi.ss.usermodel.*; 
import org.apache.poi.xssf.usermodel.XSSFWorkbook; 

import java.io.FileOutputStream; 
import java.io.IOException; 


class ExcelLineBreakWrapText { 

public static void main(String[] args) throws Exception { 

    Workbook workbook = new XSSFWorkbook(); 
    Sheet sheet = workbook.createSheet(); 

    CellStyle wrapStyle = workbook.createCellStyle(); 
    wrapStyle.setWrapText(true); 

    Row row = sheet.createRow(0); 

    Cell cell = row.createCell(0); 
    cell.setCellStyle(wrapStyle); 
    cell.setCellValue("Consommation (crédits)\r\nRéalisation (produits)"); 

    sheet.autoSizeColumn(0); 

    workbook.write(new FileOutputStream("ExcelLineBreakWrapText.xlsx")); 
    workbook.close(); 

} 
} 
관련 문제