2013-05-15 1 views
1

여기 샘플 코드는 "\의 t"입니다이의 setText 방법 작동하지?XWPFRun.setText()가 줄 바꿈이나 탭을 존중하지 않는 것 같습니까?

XWPFDocument document = new XWPFDocument(); 
XWPFParagraph tp = document.createParagraph(); 
XWPFRun tRun = tp.createRun(); 
tRun.setText("a"); 
tRun.setText("\t"); // not work 
tRun.setText("b"); 

FileOutputStream outStream = null; 
try { 
    outStream = new FileOutputStream("testTabWithPOI.doc"); 
    document.write(outStream); 
    outStream.close(); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

답변

2

을 당신이 실행에 탭이나 줄 바꿈을 추가하는 방법되지 않았는지 확인합니다. Microsoft Words가 파일을 생성하는 방식은 특별한 중단 스타일 요소를 추가하는 것이므로 Apache POI에서 수행해야하는 작업이므로 형식이 작동하는 방식입니다.

testAddTabsAndLineBreaks() of TestXWPFRun에 태그를 추가하는 예를 볼 수 있습니다.

XWPFRun tRun = tp.createRun(); 
tRun.setText("a"); 
tRun.addTab(); 
tRun.setText("b"); 

을 (당신은 너무 addTab() 지원을 위해 아파치 POI의 새 복사본을 사용해야합니다) : 코드는 할 필요가