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){ } } }
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
(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
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("${******}", "*******");