Bug 52588 - replaceText fail for tables
Summary: replaceText fail for tables
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HWPF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P5 critical with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-02 20:15 UTC by José Carlos Lacerda
Modified: 2012-10-31 11:19 UTC (History)
1 user (show)



Attachments
model file with tables (24.00 KB, application/msword)
2012-02-02 20:15 UTC, José Carlos Lacerda
Details

Note You need to log in before you can comment on or make changes to this bug.
Description José Carlos Lacerda 2012-02-02 20:15:54 UTC
Created attachment 28255 [details]
model file with tables

I have problems for to use the method Range.replaceText() for alter values into tables. When i try to alter values into tables, the file created is corrupted.

i'm using the poi-bin-3.8-beta5-20111217 version.


A simple exemple:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.Normalizer;

import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.hwpf.usermodel.Table;
import org.apache.poi.hwpf.usermodel.TableCell;
import org.apache.poi.hwpf.usermodel.TableRow;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class Tests {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		try {
		
			File arquivo = new File("C:\\in.doc");
			FileInputStream input = new FileInputStream(arquivo);
			POIFSFileSystem poi = new POIFSFileSystem(input);
			
			HWPFDocument doc = new HWPFDocument(poi);
			
			Range rg = doc.getRange();
			
			rg.replaceText("${name}", "José Carlos");
			
			FileOutputStream out = new FileOutputStream(new File("C:\\out.doc"));
			
			doc.write(out);
			out.flush();
			out.close();
			input.close();
			
		} catch (Exception e){
			
		}
		
	}
}
Comment 1 Yegor Kozlov 2012-02-07 10:09:51 UTC
I'm testing with the latest build from trunk and Excel 2007 and Excel 2010 are happy to open the generated file.

Please try with the latest build from trunk,
daily builds can be downloaded form here:
http://encore.torchbox.com/poi-cvs-build/

Yegor
Comment 2 José Carlos Lacerda 2012-02-07 18:59:19 UTC
(In reply to comment #1)
> I'm testing with the latest build from trunk and Excel 2007 and Excel 2010 are
> happy to open the generated file.
> 
> Please try with the latest build from trunk,
> daily builds can be downloaded form here:
> http://encore.torchbox.com/poi-cvs-build/
> 
> Yegor

My problem is with file Word 2003.

i'm trying open that link but it's broken
Comment 3 gbogaert62 2012-10-31 11:19:03 UTC
I have the same problem.

The output file is corrupt. MS Word can fix it but you have to save it and to "open and fix" with Word.

the code is the same : 

HWPFDocument document = new HWPFDocument(blobWord.getBinaryStream());
document.getRange().replaceText("${******}", "*******");