Java to microsoft word communication
I am a s/w engineer involved in the creation of an intranet application .One module deals with this criteria:- the details entered from the jsp page has to be converted into a to a word document.The word document has to have headers and footers.Is it possible with java.
if possible can any one help me in guiding me in the process of doing so.
The actual formatting has to take place from the file that I am creating from java.
Thanks for your suggestions in advance.
Sounds like a job to be done via OLE/ActiveX-Automation.
Would create a DLL which access Word via Automation interface to create document, put in text, do formating etc, etc. Is most easy to create this DLL with Visual C++ because they have some wizards, which can create the automation wrapper for word automatically. Doing this manually is nasty stuff.
This DLL which "rides" word can be used from your Java app via JNI.
Hope this helps.
Regards
Similar Messages
-
Can JAVA read Microsoft word document?
Hi
I am trying to make a program that read a word document, and split the document in to each pages and save each pages with file as it's footer of each pages.
--- example-----
test.doc
Page 1 |
|
|
|
|
|
footer - hi |
Page 2 |
|
|
|
|
|
footer - test |
Page 3 |
|
|
|
|
|
footer - still |
Page 4 |
|
|
|
|
|
footer - hahaha |
Page 5 |
|
|
|
|
|
footer - lastpage |
-----------------------> Out put of the program
hi.doc , test.doc, still.doc, hahaha.doc, lastpage.doc
Is there any way to import word document and process like that above?
I have searched about this, and found out 'Jakarta POI' can access to word document but with many restrictions. (I heard it doesn't support word version 2003 and 97)
Can any one please answer this?
ThankxI'm not really sure that java is the best language to use for this particular project. I haven't looked into writing a standalone application to do this sort of thing, but Microsoft Word has a built in VB editor that allows you to write scripts that will do this very simply, using Word's Document Object Model.
I would imagine the same sort of the thing could be done from a Stand-alone aplication as well, but you might need some libraries for reading the document and obtaining the object with the same model. I would look into Microsoft's .net solutions for this one. You might even be able to work out a solution in C++, C#, or even J# (which I understand is "similar" to java), if you don't know visual basic.
It is possible that there is a library out there that will read a Word Document, and create the appropriate Java object with the same object model, but I don't know where it can be found.
Anyway, if the option is available to you, take a look at Microsoft's .Net. You'll probably have more luck that way. Good Luck! -
Searching a string in Microsoft word from a Jav Application
Would appreciate if you could provide me with an example/ suggestion to search for a string in Microsoft Word document from a java aplication. Thanks
Short and rude answer: STFW.
Long and polite answer: If you use "java apache word excel" as the criterium to search the web with Google, the first hit is what we are looking for:
http://jakarta.apache.org/poi/
Good luck anyway! -
Embedding Microsoft Word in Java
Hi,
i want to embed Microsoft word in my java application. Can anyone one tell me how to embed word in java. By embedding, I don't mean to invoke word from java. I want to use word as an editor in java.
Thanks,
AshuCOM-JAVA bi-directional bridge can be used to transfer calls between Java-COM-Java. Almost all the MS products come as COM Components which by COM specifications can be reused or upgraded with out any need for recompilation.
By using bi-directionaly bridge we can make such a way that Word is extended from Canvas and add to any java component. All the connection points (In COM Tech, Connection points are used for event firing) can be converted as events and methods calls can be directed thru bridge.
I checked out JIntegra. Its good and working fine. They give u a limited time evaluation version and after that you have to pay. Check out JIntegra at linar.com
Check this thread for a sample code. It shows how I can use IE in panel.
http://forum.java.sun.com/thread.jsp?forum=57&thread=143800
Good luck,
Mohan -
In attempting to export a simple 1-page PDF file to Microsoft Word, I incessantly get the following error message:
"An error occured [sic] while trying to access the service."
Nothing on any of the community forums has helped in any way.
I have downloaded a free trial of Acrobat XI Pro -- and that too makes no difference.while trying to access the service."
That'd be associated with trying to connect to the server(s) for one of the Adobe online subscription services.
(Edit PDF or PDF Pack)
These online services are separate and independent of the desktop application Acrobat.
It appears that you have had / are having internet connection issues.
Be well... -
Access microsoft word doc using java
how can i access microsoft word using java .
I want to select text from the word in the same format as it is.
if possible can u all help meBy using an appropriate library. JText, whatever.
Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks. -
Interaction with Microsoft Word using Java Programming
writing Text ON TO MICROSOFT WORD USING java Programming Urgently required
Go throuh jakarta POI(hssf) to do..No! HSSF which stands for Horrible SpreadSheet Format can be used for Excel (spreadsheets as the name suggests). For Word, you would need to lok at HPSF.
-
Invoking Microsoft Word from Java code
I want to invoke Microsoft word from Java code. How can i do this plz ............... Help
do something along these lines.... here is an example with notepad
create a .bat file with the commmand in to run notepad for example
notpad c:\test.txtthis command calls notepad and passes it the argument C:\test.txt which is the file and it's location, that I want to open.
The Java program
import java.util.*;
import java.io.*;
public class Run
public static void main(String args[])
try
//the name of the batch file with your commands in
String command ="runprog.bat";
//get the runtime
Runtime rt = Runtime.getRuntime();
//run the bat file
Process proc = rt.exec(command);
//wait for the program to exit i.e notepad then get the return code
int exitVal = proc.waitFor();
//print out the exit value
System.out.println(2THe Process exit value is: " + exitVal);
catch(Throwable t)
t.printStackTrace();
}have a look at this
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
and this
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html -
Printing a microsoft word doc using Java Print API
Hi,
I have to print a microsoft word doc.I am using Java Print API, but the code is printing only Hashcodes instead of the actual document.
Here is the code. Please let me know whats wrong in it.
CODE:::
public String print() throws Exception {
String realPath = getRealPath("/images/formLibrary/csaAddressContactRequestForm100.doc");
PrintRequestAttributeSet pras1 = new HashPrintRequestAttributeSet();
DocFlavor flavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = defaultService.createPrintJob();
FileInputStream fis1 = new FileInputStream(realPath);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc1 = new SimpleDoc(fis1, flavor1, das);
job.print(doc1, pras1);
Thread.sleep(10000);
System.exit(0);
return "";
}By using an appropriate library. JText, whatever.
Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks. -
Connecting Java Application with Microsoft Word Toolbar
My project involves designing a GUI with which I will use Java for. And I also have to create a Microsoft Word Toolbar that will open the Java GUI. There will be other interactions between both the GUI and the toolbar.
Is that possible? Or shall I use Visual Basic or .NET for the GUI?
Advice appreciated please!hi
check this
http://help.sap.com/javadocs/NW04/current/bi/docs/connectors/sapq_howto.html
let me know am i reached ur point
bvr -
Can Java be used to parse Microsoft Word(.doc) files?
Hi guys ,
I want to know whether Java can be used to parse Microsoft Word(.doc) files for searching a string or for checking for grammatical errors, etc
Thanks in advance.
AvichalHey man, anything and every thing can be done these days.
About ur question doc is like all other normal text files with some extra features and extra character supports and other stuffs.
If u neglect those parts and if u consider it to be a normal text file then its a much simpler job.
Here is a code that searches for the key word in all the doc files, txt files, pdf files and html files
in the mentioned folder and sub folders. Any way its a servlet u can change it to a normal program.
It first check the file to know whether they are doc, pdf, html or txt files if yes then it will read the file and
store the contents in the vector and parse the vector for the search string and display the result.
Along with the result the below code will also display the time taken and the number of search string found in the document
import java.io.*;
import java.util.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class search_local extends HttpServlet
public void service( HttpServletRequest _req, HttpServletResponse _res ) throws ServletException, IOException
long startTime = System.currentTimeMillis();
File RootDir = new File( _req.getRealPath( "/docs/" ) );
if ( RootDir.isDirectory() == false )
System.out.println( "Invalid directory" );
_res.setStatus( HttpServletResponse.SC_NO_CONTENT );
return;
Vector kList = new Vector( 3 );
StringTokenizer st = new StringTokenizer( _req.getParameter( "search_text" ), "+" );
while ( st.hasMoreTokens() )
kList.addElement( st.nextToken().trim() );
//- Run through list
Vector toBeDone = new Vector( 10 );
Vector found = new Vector( 10 );
String dir[] = RootDir.list( new htmlFilter() );
cDirInfo tX = new cDirInfo( RootDir, dir );
toBeDone.addElement( tX );
while ( toBeDone.isEmpty() == false )
tX = (cDirInfo)toBeDone.firstElement();
try
int x = 0;
for ( ;; )
File newFile = new File( tX.rootDir, tX.dirList[x] );
if ( newFile.isDirectory() )
File t = new File( tX.rootDir, tX.dirList[x] );
String a[] = newFile.list( new htmlFilter() );
toBeDone.addElement( new cDirInfo( t, a ) );
else
int freq = searchFile( kList, newFile );
if ( freq != 0 )
found.addElement( new cPage( freq, newFile ) );
x++;
catch( ArrayIndexOutOfBoundsException E ){}
toBeDone.removeElementAt(0);
dir = null;
long totalTime = System.currentTimeMillis() - startTime;
formatResults( found, kList, totalTime, _req.getRealPath( "/docs" ), _res );
private void formatResults( Vector _fList, Vector _kList, long time, String _root, HttpServletResponse _res ) throws IOException
_res.setContentType("text/html");
PrintWriter Out = new PrintWriter( _res.getOutputStream() );
Out.println( "<HTML><HEAD><TITLE>Search results</TITLE></HEAD>" );
Out.println( "<BODY><H3>Search Results</H3><BR>" );
Out.println( "Keywords:<B> " );
Enumeration E = _kList.elements();
while ( E.hasMoreElements() )
Out.println( (String)E.nextElement() + " : " );
Out.println( "</B><BR><BR><CENTER><HR WIDTH=100%></CENTER><BR>" );
E = _fList.elements();
cPage sPage;
String link;
while ( E.hasMoreElements() )
sPage = (cPage)E.nextElement();
link = sPage.cFile.toString();
link = "http://localhost/BugFix/docs/" + link.substring( link.indexOf( _root )+_root.length(), link.length() );
Out.println( "<FONT SIZE=+1><A HREF=" + link + ">" + sPage.cFile.getName() + "</A></FONT>" );
Out.println( "<FONT SIZE=-2>(" + sPage.freq + ")</FONT><BR>" );
if ( _fList.size() == 0 )
Out.println( "<I><B>No sites found!</I></B><BR>");
Out.println( "<BR><CENTER><HR WIDTH=100%></CENTER>" );
Out.println( "<BR><FONT SIZE=-1>Time to complete: " + ((double)time/1000) + " seconds</FONT>" );
Out.println( "</BODY></HTML>" );
Out.flush();
private int searchFile( Vector _klist, File _filename )
//- Links the file
int frequency=0;
try
DataInputStream In = new DataInputStream( new FileInputStream( _filename ) );
String LineIn, token;
boolean bValid = true;
Enumeration E;
cLineParse lp;
while ( (LineIn = In.readLine()) != null )
lp = new cLineParse( LineIn.toUpperCase() );
while ( (token=lp.nextToken()) != "" )
if ( token.indexOf( "<" ) != -1 && (
token.indexOf( "<A" ) != -1 ||
token.indexOf( "<HE" ) != -1 ||
token.indexOf( "<APP" ) != -1 ||
token.indexOf( "<SER" ) != -1 ||
token.indexOf( "<TEX" ) != -1 ))
bValid = false;
else if ( token.indexOf( "<" ) != -1 && (
token.indexOf( "</A" ) != -1 ||
token.indexOf( "</HE" ) != -1 ||
token.indexOf( "</APP" ) != -1 ||
token.indexOf( "</SER" ) != -1 ||
token.indexOf( "</TEX" ) != -1 ))
bValid = true;
else if ( bValid )
E = _klist.elements();
String key;
while ( E.hasMoreElements() )
key = ((String)E.nextElement()).toUpperCase();
if ( token.indexOf( key ) != -1 )
frequency++;
In.close();
catch( IOException E ){}
return frequency;
class cPage extends Object
public int freq;
public File cFile;
public cPage( int _freq, File _cFile )
freq = _freq;
cFile = _cFile;
//- End of file
//----- Supporting classes
class htmlFilter implements FilenameFilter
public boolean accept(File dir, String name)
File tF = new File( dir, name );
if ( tF.isDirectory() )
return true;
int indx = name.lastIndexOf( "." );
if ( indx == -1 )
return false;
String Ext = name.substring( indx+1, name.length() ).toLowerCase();
if ( Ext.equals( "html" ) ||
Ext.equals( "pdf" ) ||
Ext.equals( "txt" ) ||
Ext.equals( "doc" ) )
return true;
return false;
class cDirInfo
public File rootDir;
public String[] dirList;
public cDirInfo( File _r, String[] _d )
rootDir = _r;
dirList = _d;
class cLineParse
String L;
public cLineParse( String _s )
L = _s;
public String nextToken()
String ns="";
boolean bStart = false;
for ( int x=0; x < L.length(); x++ )
if ( L.charAt(x) == '<' && ns.length() != 0 )
L = L.substring( x, L.length() );
return ns;
else if ( L.charAt(x) == '<' )
ns = ns + L.charAt( x );
bStart = true;
else if ( L.charAt(x) == '>' ||
L.charAt(x) == '\r' ||
( L.charAt(x) == ' ' && bStart == false ) )
ns = ns + L.charAt( x );
L = L.substring( x+1, L.length() );
return ns;
else
ns = ns + L.charAt( x );
L = "";
return ns;
} -
Copying from Oracle SQL Developer Worksheet doesn't retain formatting (font,color etc...)in Microsoft Word but copying from other programs such as
visual studio, chrome browser etc works fine. This doesn't work even after changed the setting to Keep Source formatting of Options-> Copy and Paste SettingsHi,
I notice that you have cross posted in Answers forum and Oracle forum. Have you tried Mr. Peter's suggestion?
Then, I recommend we check the Word settings:
1. Go to: Options > Advanced > Cut, Copy and Paste
2. Make sure that Use smart cut and paste is ticked.
3. Click the Settings button next to this option
4. Make sure that Smart Style
Behavior is checked.
If the issue still exists, please upload a sample through One Drive, I want to test.
Regards,
George Zhao
TechNet Community Support -
Product Key for Microsoft Word is not working
I just recently purchased Microsoft word 2011 for my new Macintosh and the product key that you e-mailed me keeps showing up as invalid? What should I do?
Hi,
For issues about Invalid product key errors in Office for Mac 2011, you can refer to this kb below:
http://support.microsoft.com/kb/2390862/en-us
Please try the methods in this kb, verify that the correct product key is entered, troubleshoot the Operating System or obtain a replacement product key to try again.
If none of them helps, since we only provide support for Office for Windows in this forum, you should post the question to Office for Mac forum:
http://answers.microsoft.com/en-us/mac
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Regards,
Melon Chen
TechNet Community Support -
I typed a 10 page paper. And when I went to submit it to my class online the document was grey and it had no information and it wouldn't let me open it; like it was corrupted. When I do click on it, it says that Microsoft Word is unable to find my document.
When I click would you like to locate it yourself, it brings me to all my documents but it is no where to be found on my computer. How do I retrieve it?Hi Jessica,
From where did you open the file for editing originally? Have you saved it properly before you submit it?
As Paul mentioned above, in some cases, corrupted documents are rarely recoverable. Do you have a backup of that file? Or elaborate a little bit about your situation for further assistance.
Regards,
Ethan Hua
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs. -
I hope this will save other developers some time.
This may be obvious to others, but I just spent several hours Googling and testing to determine what actually happens when a user copies text containing "Smart Quotes" from Microsoft Word into a Java JTextComponent. For those not familiar with Smart Quotes, by default, MS Word changes double-quoted strings from using the US-ASCII character for quote (0x22) into left- and right- curly quotes (UTF-16: 0x201c and 0x201d). Word also does this with serveral other characters. This plays havoc with the display and Java Strings later encoded with java.beans.XMLEncoder, unless treated carefully. Here is what I discovered (obviously, this applies to MS Windows):
All values are in hexadecimal.
- Word is storing the character for double quote as UTF-16 internally (201C).
- When the character is copied to the clipboard, it is copied as UTF-8 (E2 80 9C).
- When the clipboard is pasted into Java, Java is assuming the it was originally Windows-1252 encoded, because that is the default for the US-EN locale in Windows XP (probably also Vista, but I only tested in XP).
- Java translates this into a-circumflex, euro-sign, o-e-ligature, the characters corresponding to E2, 80, and 9C respectively in Windows-1252 and represents it internally in UTF-16 as 00E2 20AC 0153.
-When the String is XML-encoded using java.beans.XMLEncoder, it is written in UTF-8 as C3A2 E282AC C593, which equates to UTF-16 00E2 20AC 0153 -- the characters a-circumflex, euro-sign, o-e-ligature.
I am not sure how to fix this, but maybe another reader does. I am experimenting with the Clipboard (java.awt.datatransfer) to see if I can programmatically find out the original character encoding (in this case, UTF-16).Doesn't the DataFlavor contain the character encoding? What is the content of the InputStream returned by
InputStream is = (InputStream)contents.getTransferData(DataFlavor.getTextPlainUnicodeFlavor());
If I use
DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
String mimeType = df.getMimeType();
String encoding = mimeType.replaceAll(".*?charset=(.*?)\\s*$", "$1");
InputStream is = (InputStream) contents.getTransferData(df);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) != -1;)
baos.write(buffer, 0, count);
baos.close();
result = baos.toString(encoding);to transfer
Hello "World"
which Word changes the quotes to the smart 'smart quotes' version I get as a result
Hello World
which is what I expect.
Am I missing something?
Edited by: sabre150 on Sep 4, 2009 1:27 PM
Maybe you are looking for
-
How to do reconcilization of ODS data and CUBE data
Hi All, How to do reconciliation of ODS data and CUBE data,I know how to do reconciliation of R/3 data and BW data. Regards. hari
-
Why does while loop pause during operation
Hi everyone, I have written the attached code which will eventually be a part of a bigger program. The program is intended to log some test value, in this case just the date and time to a csv file when a button is pressed (log in WHITE, loop1). Lo
-
Duplicate Meetings when Syncing with Outlook
Outlook meeting sometimes (but not always) end up being duplicated in my desktop Outlook after I synchronize using Blackberry Desktop Manager. If I could avoid this duplication, I would like to keep wireless calendar from my work Outlook but I am wo
-
OSB 10.3 connectivity to Database: Recommended approach?
Hi OSB 10.3 doesnt yet provide JCA adapter framework to connect to database. In Oracle integration world, this is one of the foundational requirement. We understand that we can write and call a BPEL wrapper and fetch data using SOA suite DB adapter.
-
TS1470 iphone cannot restore this time because the server cannot be contacted at this time
can anyone help me? my iphone 4 6.1.2 is jailbroken and i cannot turn on or off my iphone its stuck with apple logo