0
실제로 저는 스윙 플랫폼에 익숙하지 않지만 어떻게 든 워드 문서의 총 줄 수를 계산하는 코드를 만들었지 만 지금은 단어 문서의 총 문자 수를 계산해야합니다.스윙을 사용하여 단어 문서 (.docx)의 총 문자 수를 계산합니다.
여기 Swing을 사용하여 단어 문서의 줄 수를 계산하는 코드입니다. 단어 수를 계산하려면 어떻게해야합니까?
public void actionPerformed(ActionEvent e) {
if(e.getSource()==openfile){
JFileChooser fc=new JFileChooser();
int i=fc.showOpenDialog(this);
if(i==JFileChooser.APPROVE_OPTION){
File f=fc.getSelectedFile();
String filepath=f.getPath();
JT_Filechooser.setText(filepath);
JT_FileName.setText(f.getName());
try{
FileInputStream fis = new FileInputStream(f.getAbsolutePath());
XWPFDocument document = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = document.getParagraphs();
int count = 0;
for (XWPFParagraph para : paragraphs) {
count++;
System.out.println(para.getText());
}
System.out.println("No. of lines : "+count);
JT_LinesCount.setText(Integer.toString(count));
fis.close();
}catch (Exception ex) {ex.printStackTrace(); }
}
}
}
매트 덕분에 – vasanth
을 사용해 보도록하겠습니다. 제 출력물을 얻었습니다. 고마워. – vasanth