473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to hide the data in between the two tags(<hidden> .. </hidden>) in Word document

I am able to Read the input document using Apache POI and also able to find the data between the tags(What to be hidden) but the problem is i'm unable to write the data in the output file. How can i do the same to write the data and hide it in the output generated file..

For more check the following attachments where the input file has the data with the tags(<hidden>..... </hidden>) and whereas the output file has the data hidden (to check it use Hide/Show toggle box in the toolbar)


Expand|Select|Wrap|Line Numbers
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.FileOutputStream;
  4. import org.apache.poi.hwpf.HWPFDocument;
  5. import  org.apache.poi.hwpf.extractor.WordExtractor;
  6. import org.apache.poi.hwpf.usermodel.CharacterRun;
  7. import org.apache.poi.hwpf.usermodel.Range;
  8.  
  9.  
  10. public class Hidden {
  11.     public static void main(String args[]) throws Exception
  12.     {
  13.         File file = new File("D://me1.doc");
  14.         FileInputStream fin = new FileInputStream(file);
  15.         FileOutputStream fout = new FileOutputStream("D://Test.doc");
  16.         HWPFDocument doc = new HWPFDocument(fin);
  17.         Range range = doc.getRange();    
  18.         WordExtractor extractor = new WordExtractor(doc);
  19.         String para[] = extractor.getParagraphText();    
  20.         String output="";
  21.         String hidden="";
  22.         for (String p : para) {
  23.             String[] w = p.split("[<\\>]");             
  24.             for(int k=0 ;k<w.length;k++){
  25.                 if(w[k]!=null && !"".equalsIgnoreCase(w[k])){
  26.                     if("hidden".equalsIgnoreCase(w[k])){                            
  27.                         k++;
  28.                         CharacterRun  run = range.getCharacterRun(k);
  29.                         hidden= w[k];
  30.                         k++;                       
  31.                         System.out.println(hidden);
  32.                         run.setVanished(true);
  33.                         doc.write(fout); 
  34.                     }else{
  35.  
  36.                     }
  37.                 }
  38.             } 
  39.         }
  40.         fout.close();
  41.         fin.close();
  42.     }
  43.  
  44.  
Attached Files
File Type: doc INPUTFILE.doc (22.5 KB, 172 views)
File Type: doc OUTPUTFILE.doc (23.0 KB, 194 views)
May 16 '13 #1
0 1333

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Erik Ronne | last post by:
Hello Gurus I have an intranet web page with links to all kinds of Microsoft Word document that we use at my work, so my co-works can go to the web page when they need a special document....
1
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
0
by: MartinABeck | last post by:
I am trying to put a word document into a c# program the same as described at this link http://support.microsoft.com/?id=304662 . I have been able to get this to work but I am in need of the file...
1
by: Stu | last post by:
Hi, I am trying to extract the values from a few specific fields in a word document from VB. I have now opened the doc and can loop through all the paragraphs...but none of the tables are...
10
by: Noor | last post by:
Hi all, I need to well formatted ms word document through vb.net. All the data that will make the word document will come from the database. and formatted dynamically. Currently i have...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
3
Gyanchand
by: Gyanchand | last post by:
Hey All, Need to send data from an ASP file to a word document.....Can anyone help me with this
2
by: beemomo | last post by:
I have some invoice data on an MS Access form, and I wish to export the data into Microsoft Word document, can anyone help me please? Many thanks..
0
by: cholletivinod | last post by:
Hi friends , am creating one application in dat i want to replace particular text(<<ABC>>) with a table in word document am using below code but am getting text if i open the...
2
by: allan.s.palmer | last post by:
Hello, I have an asp.net pop up that is generating a Word document real time and sending it to the user by sending the appropriate response headers. When it is run on our development environment...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.