How to parse and edit MS Visio file in java code - java

I have checked multiple links and two options were shown for editing MS visio file in Java code.
Apache POI - HDGF and XDGF - Java API To Access Microsoft Visio Format Files
Aspose.diagram APIs
Has anyone done any coding in Java language using above option?
I am using eclipse IDE.
Also please suggest if there is third better way to edit MS visio file using java code.

If you are talking about libraries, these are the two basically. Apache POI AFAIK can't create diagrams, only read, if I am not mistaking - but please verify, maybe something changed since I last looked at that ten years ago.
So this basically leaves you with a single choice. Or you can always spend a few years and write it all yourself. Well, man does not simply walk into mordor create visio files with java.
Maybe you could consider using SVG instead, that can be generated and consumed by basically anything? Visio can also read and write SVG out of the box.

Related

API to read, write and manipulate msword files

I want to write some java code to read, write, edit and do other things with sets of Microsoft Word files (different Word versions). What is the best API for this, and how do I get started?
P.S. I searched StackOverflow and found that this question has been asked before, but several years ago. I would like to know the best available API today. Thanks.
Check out apache POI : https://poi.apache.org/
As quoted on their website.. "Apache POI - the Java API for Microsoft Documents"
Personally I have only used this for EXCEL spreadsheet manipulation, but it does support word documents as well...
The best part is it's open source and completely free!

How to manage excel sheets in excel file using java without using 3rd party libraries

I has a excel file with 4 excel sheets in it. Now i want to read or write to required excel sheets using java without using any third party lib.
I know i can read and write data using FileInputStream and FileOutputStream respecitvely. But i can handle the work sheets??
No, you can'not, There is numerous way in Java for reading/writing files, but there is no built-in support for MS Office/Excel spreadsheets. http://poi.apache.org/ - is a key to victory.
If your goal is to interface with data from an excel sheet from your Java application, I'd suggest to use the solutions suggested by other posters, it will save you a lot of work.
If, however, you want to be able to read excel files from Java (or any other programming language for that matter) 'just because you can' then you could take a look at this file and read the instructions on this web-page. I would warn you that it would take considerably more time to implement your own API if you base it only on the file-specs that are publicly available. You might want to check out the work done by the people from the Apache POI project to get an idea of how to approach it. Or (even better) contribute to the project. Here you can find out how to go about doing that

Java libraries that work with Microsoft Office documents but do not depend on automation

By "not depend on automation", I mean that it should not require a Microsoft Office installation to work; let alone interact with a live instance of a Microsoft Office component. One such library is Aspose.Total for Java. Are there any more out there?
Another solution I'm considering is to use OpenOffice.org. However, I'm not sure if I'm going to run into the same problems as with Microsoft Office as detailed here.
For Office Documents: http://poi.apache.org/
I have not tried this myself, but Apache usually deliver good libraries
For just Excel: JExcel API for Java
I use this for one application, and it works quite well. May use a fair bit of RAM for larger documents.
One designed specifically to with with the newer XML formats is docx4j: http://dev.plutext.org/trac/docx4j
There are two further answers for this question. Depending on your application.
can borrow from the OpenOffice library code that deals with opening and saving MS Office files. (See: http://www.artofsolving.com/opensource/jodconverter or jOpenDocument )
You might just use OpenOffice itself by scripting or automating that.
I faced this question a while back with a Ruby app and because I was in control of the source document, I got the originator to save things as HTML format and used Tidy to filter the junk. Another option it to find a tool to convert the Office files to RTF which is more generic.
Another to consider ...
LibreOffice looks useful.
jExcelAPI if you just want excel.
Finally there are some opportunities on sourceForge, try this search: http://sourceforge.net/search/?q=java+ms+office
You may find spreadsheets BIG unless you use OpenOffice or MS Office because you need to have a fancy shamancy virtual sparse matrix to do what they do well.
ODF Toolkit - http://odftoolkit.org

How can I read MS Office files in a server without installing MS Office and without using the Interop Library?

The interop library is slow and needs MS Office installed.
Many times you don't want to install MS Office on servers.
I'd like to use Apache POI, but I'm on .NET.
I need only to extract the text portion of the files, not creating nor "storing information" in Office files.
I need to tell you that I've got a very large document library, and I can't convert it to newer XML files.
I don't want to write a parser for the binaries files.
A library like Apache POI does this for us. Unfortunately, it is only for the Java platform. Maybe I should consider writing this application in Java.
I am still not finding an open source alternative to POI in .NET, I think I'll write my own application in Java.
For all MS Office versions:
You could use the third-party components like TX Text Controls for Word and TMS Flexcel Studio for Excel
For the new Office (2007):
You could do some basic stuff using .net functionality from system.io.packaging. See how at http://msdn.microsoft.com/en-us/library/bb332058.aspx
For the old Office (before 2007):
The old Office formats are now documented: http://www.microsoft.com/interop/docs/officebinaryformats.mspx. If you want to do something really easy you might consider trying it. But be aware that these formats are VERY complex.
Check out the Aspose components. They are designed to mimic the Interop functionality without requiring a full Office install on a server.
As the new docx formats are inherently XML based files, you can create and manipulate them programmatically with standard XML DOM techniques, once you know the structure.
The files are basically zip archives with an alternate file extension. Use the System.IO.Packaging namespace to get access to the internal elements of the file, then open them into a XmlDocument to perform the manipulation.
There are examples available for doing this, and the Office Open XML project on SourceForge may be worth looking at for inspiration.
As for the older binary formats, these were proprietary to MS, and the only way you're likely to get at the content from within is through the Office object model (requires an Office install), or a third party file converter/parser.
Unfortunately there's nothing first party and native to the .NET platform to work with these files.
What do you need to do with those file? If you just want to stream them to the user, then the basic file streams are fine. If you want to create new files (perhaps based on a template) to send to the user that the user can open in Office, there are a variety or work-arounds.
If you're actually keeping data in Office documents for use by your web site, you're doing it wrong. Office documents, even Excel spreadsheets and access databases, are not really an appropriate choice for use with an interactive web site.
If the document is in word 2007 format, you can use the system.io.packaging library to interact with it programatically.
RWendi
In Java world, there is also JExcelApi. It is very clearly written, from what I was able to see, much cleaner then POI. So maybe even a port of that code to .NET is not out of the question, depending of course you have enough of time on your hands.
OpenOffice.
You can program against it and have it do a lot for you, without spending the money on a license for the server, or have the vulnerability associated with it on your server.
Microsoft Excel workbooks can be read using an ODBC driver (or is it an OLE DB driver? can't remember) that makes the workbook look like a database table. But I don't know whether that driver is available without the Office Suite itself.
You can use OpenOffice. It has a command-line conversion tool:
Conversion Howto
In short, you define a macro in OpenOffice and you call that macro with a command-line
argument to OpenOffice. In that argument the name of the local file (the Office file) is
encoded.
It's not a great sollution, but it should be workable.

Can Java POI write image to word document?

Anyone know if it is possible?
And got any sample code for this?
Or any other java API that can do this?
The Office 2007 format is based on XML and so can probably be written to using XML tools. However there is this library which claims to be able to write DocX format word documents.
The only other alternative is to use a Java-COM Bridge and use COM to manipulate word. This is probably not a good idea though - I would suggest finding a simpler way.
For example, Word can easily read RTF documents and you can generate .rtf documents from within Java. You don't have to use the Microsoft Word format!
As others have said POI isn't going to allow you to do anything really fancy - plus it doesn't support Office 2007+ formats. Treating MS Word as a component that provides this type of functionality via COM is most likely the best approach here (unless you are running on a non-Windows OS or just can't guarantee that Word will be installed on the machine).
If you do go the COM route, I recommend that you look into the JACOB project. You do need to be somewhat familiar with COM (which has a very steep learning curve), but the library works quite well and is easier than trying to do it in native code with a JNI wrapper.
If you are using docx, you could try docx4j.
See the AddImage sample
Surely:
Take a look at this: http://code.google.com/p/java2word
Word 2004+ is XML based. The above framework gets the image, convert to Base64 representation and adds it to the XML.
When you open your Word Document, there will be your image.
Simple like this:
IDocument myDoc = new Document2004();
myDoc.getBody().addEle("path/myImage.png"));
Java2Word is one API to generate Word Docs using obviously Java code. J2W takes care of all implementation and XML generation behind the scenes.
As far as can be gathered from the project website: no.
POI's HWPF can extract an MS Word document's text and perform simple modifications (basically deleting and inserting text).
AFAIK it can't do much more than that.
Also keep in mind that HWPF works only with the older MS Word (97) format, not the latest ones.
Not sure if Java out of the box can do it directly. But i've read about a component that can pretty much do anything in terms of automating word document generation without having Word. Aspose Words
JasperReports uses this API alternatively to POI, because it supports images:
JExcelAPI
I didn't try it yet and don't know how good/bad it is.

Categories

Resources