Programming

풍부한 Word 문서를 만들 수있는 Java API가 있습니까?

procodes 2020. 8. 4. 19:15
반응형

풍부한 Word 문서를 만들 수있는 Java API가 있습니까? [닫은]


테이블, 그래프, 목차 및 텍스트가 포함 된 Word 문서를 생성해야하는 곳에서 작업 할 새 앱이 있습니다. 이것에 사용하기에 좋은 API는 무엇입니까? 그래프, 목차 및 표를 지원 하는가? 그것들을 사용하는 데 숨겨진 숨겨진 것들은 무엇입니까?

몇 가지 설명 :

  • PDF를 출력 할 수없고 Word 문서를 원합니다.
  • OpenOffice가 아닌 MS Word 2003 (또는 2007)을 사용하고 있습니다.
  • * nix 앱 서버에서 응용 프로그램이 실행되고 있습니다

템플릿 문서로 시작하여 테이블, 그래프 등으로 일부 공간을 채울 수 있다면 좋을 것입니다.

편집 : 아래에 몇 가지 좋은 답변이 있습니다. 각각 내 현재 상황까지 자체 결함이 있습니다. 그들로부터 "최종 답변"을 고르기가 어렵다. 내가 열어두고 더 나은 솔루션이 만들어지기를 바랍니다.

편집 : OpenOffice UNO 프로젝트가 내가 요청한 것에 가장 가까운 것 같습니다. POI는 확실히 더 주류이지만, 내가 원하는 것에 너무 미숙합니다.


2007 년 프로젝트 는 Java 웹 응용 프로그램 (Struts / JSP 프레임 워크)에서 MS-Word 호환 문서 (* .doc)와 해당 PDF 문서를 프로그래밍 방식으로 생성하기 위해 OpenOffice.org의 UNO ( Universal Network Objects ) 인터페이스를 성공적으로 사용 했습니다.

OpenOffice UNO를 사용하면 MS-Office 호환 차트, 스프레드 시트, 프레젠테이션 등을 작성할 수 있습니다. 차트 및 테이블을 포함한 정교한 Word 문서를 동적으로 작성할 수있었습니다.

소프트웨어가 컨텐츠를 삽입 한 책갈피 삽입이있는 템플리트 MS-Word 문서를 사용하여 프로세스를 단순화했지만 문서를 처음부터 완전히 작성할 수 있습니다. 이 소프트웨어의 목표는 최종 사용자가 최종 제공 및 보관을 위해 PDF로 변환하기 전에 최종 사용자가 공유하고 추가로 조정할 수있는 보고서 문서를 소프트웨어에서 생성하도록하는 것입니다.

사용자가 MS-Office 대신 OpenOffice를 사용하도록하려는 경우 OpenOffice 형식의 문서를 선택적으로 생성 할 수 있습니다. 이 경우 사용자는 MS-Office 도구를 사용하려고합니다.

UNO는 OpenOffice 제품군에 포함되어 있습니다. 우리는 단순히 Java 앱을 제품군 내의 UNO 관련 라이브러리에 연결했습니다. 예제 응용 프로그램 및 UNO 개발자 안내서가 포함 OpenOffice SDK ( Software Development Kit )를 사용할 수 있습니다.

최신 OpenOffice UNO가 MS-Office 2007 Open XML 문서 형식을 생성 할 수 있는지 여부는 조사하지 않았습니다.

OpenOffice UNO의 중요한 점은 다음과 같습니다.

  1. 프리웨어입니다
  2. 여러 언어 (예 : Visual Basic, Java, C ++ 등)를 지원합니다.
  3. 플랫폼 독립적입니다 (Windows, Linux, Unix 등).

다음은 유용한 웹 사이트입니다.


Apache POI 가 그 일을 할 수 있다고 생각 합니다. HWPF가 아직 초기 개발 중이라는 사실 때문에 사용 목적에 따라 가능한 문제가 발생할 수 있습니다.

HWPF 는 Java 만 사용하여 Microsoft Word 97 (-XP) 문서를 읽고 쓰는 API 세트입니다.


이것을 사용할 수 있습니다 : http://code.google.com/p/java2word

Java2Word라는이 API를 구현했습니다. 몇 줄의 코드로 하나의 Microsoft Word 문서를 생성 할 수 있습니다.

예 :

IDocument myDoc = new Document2004();
myDoc.getBody().addEle(new Heading1("Heading01"));
myDoc.getBody().addEle(new Paragraph("This is a paragraph...")

사용 방법에 대한 몇 가지 예가 있습니다. 기본적으로 하나의 jar 파일이 필요합니다. 설정 방법에 대한 추가 정보가 필요하면 알려주십시오.

* 프로젝트에서 하나의 진짜 필요성이 있었기 때문에 이것을 썼습니다. 내 블로그에서 더 많은 것 :

http : //leonardo-pinho.blogspot.com/2010/07/java2word-word-document-generator-from.html *

건배 레오나르도

편집 : 링크의 프로젝트가 https://github.com/leonardoanalista/java2word 로 이동되었습니다.


Java 용 Aspose.Words를 사용해보십시오. Java가 설치된 모든 OS에서 실행됩니다.

MS Word 출력 형식이 필요한 경우 문서를 DOC, DOCX 또는 RTF로 출력합니다. 모두 동일하게 지원됩니다.

이 API를 사용하면 문자 그대로 노드에서 문서를 처음부터 작성하고 형식 특성을 설정할 수 있습니다. 또한 테이블 행 만들기, 필드 삽입 등과 같은 고급 방법을 제공하는 DocumentBuilder를 사용할 수도 있습니다. 또는 기존의 사전 생성 된 문서간에 부분을 복사 / 결합 / 이동할 수 있습니다 (계약을 모으고 싶다고 말합니다). 여러 문서의 문서와 Aspose.Words는 결과 문서에 스타일, 목록 서식 등을 올바르게 병합합니다.

Aspose.Words를 사용하여 TOC 필드를 삽입 할 수 있지만 오늘 현재 Microsoft Word에서 문서를 열면 TOC 필드에 필드 업데이트가 필요합니다. 그러나 2010 년 초 TOC 필드에 대한 완벽한 지원을 발표 할 예정입니다. 예를 들어 MS Word와 마찬가지로 완전한 TOC를 구축 할 것입니다.

저는 Aspose.Words 팀에 있습니다.


한 번만 언급되었으므로 docx4j 라이브러리를 호출하고 싶습니다. docx4j에서 다른 것보다 더 많은 성공을 거두었 기 때문입니다. Apache POI의 Word 문서 지원은 그리 좋지 않습니다. 또한 Aspose.Words와 달리 docx4j는 오픈 소스 라이브러리입니다.

유일한 단점은 docx4j를 사용하면 OLE2 기반 (doc) 형식 문서 대신 Office Open XML (docx) 형식 문서를 만들어야한다는 것입니다. 이 형식은 Word 2007의 기본 형식이지만 Word 2003 및 이전 사용자는 호환 기능 팩을 설치해야합니다.


Java 용 Aspose.Words사용해보십시오 .

Aspose.Words for Java는 Java 응용 프로그램 내에서 직접 광범위한 문서 처리 작업을 수행 할 수있는 Java 용 고급 (상업용) 클래스 라이브러리입니다.

Aspose.Words for Java supports DOC, OOXML, RTF, HTML and OpenDocument formats. With Aspose.Words you can generate, modify, and convert documents without using Microsoft Word.


You can use a Java COM bridge like JACOB. If it is from client side, another option would be to use Javascript.


I've used Aspose.Words to do mail merge in .NET. I believe that they also have a Java version.


There's a tool called JODConverter which hooks into open office to expose it's file format converters, there's versions available as a webapp (sits in tomcat) which you post to and a command line tool. I've been firing html at it and converting to .doc and pdf succesfully it's in a fairly big project, haven't gone live yet but I think I'm going to be using it. http://sourceforge.net/projects/jodconverter/


iText is really easy to use.

If you requiere doc files you can call abiword (free lightweigh multi-os text procesor) from the command line, it has several conversion format convert options.


docx4j or poi, both of which are ASL v2

@wondersofcomputing: iText is actually free and open source


After a little more research, I came across iText, a PDF and RTF-file creation API. I think I can use the RTF generation to create a Doc-readable file that can then be edited using Doc and re-saved.

Anyone have any experience with iText, used in this fashion?

Bill, the POI and iText API are very similar from a programming perspective. I've worked with both in the past and found them both easy to use and well documented.

With iText you gain the advantage of being able to switch between formats (RTF and PDF) with minor change to the code. If I remember correctly the content is laid out using the same calls and then set as PDF or RTF using a few lines of code.

However I believe the formatting in RTF is limited compared to DOC. I don't know if you'll be able to implement the advanced features you are looking for (tables, inline images) without a decent amount of hassle, if at all.

Given what you said that about HWPF not having enough functionality for your needs (I've only dealt with the Excel side of POI) your best bet may be to convince the powers that be that PDF is the best technology for the job.


I have developed pure XML based word files in the past. I used .NET, but the language should not matter since it's truely XML. It was not the easiest thing to do (had a project that required it a couple years ago.) These do only work in Word 2007 or above - but all you need is Microsoft's white paper that describe what each tag does. You can accomplish all you want with the tags the same way as if you were using Word (of course a little more painful initially.)


After a little more research, I came across iText, a PDF and RTF-file creation API. I think I can use the RTF generation to create a Doc-readable file that can then be edited using Doc and re-saved.

Anyone have any experience with iText, used in this fashion?


Yet another possibility, since this is a web app.

I was able to render an HTML page with the MIME type set to "application/msword", which caused the browser to spawn Word which imported the html just fine, allowing edits and saving just as if I'd output a real Word doc.

Tables work fine, but images I hadn't gotten working yet. It may be as easy as just an tag in the HTML, or I may have to stream a separate part of the response containing the image data in binary, or some other method I haven't come up with yet. :)


Even though this is much later than the request, it might help others. Docmosis provides a Java API for creating documents in doc,pdf,odt format using documents as templates. It uses OpenOffice as the engine to perform the format conversions. Document manipulation and population is performed by Docmosis itself.

참고URL : https://stackoverflow.com/questions/203174/is-there-a-java-api-that-can-create-rich-word-documents

반응형