You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by 上善 <11...@qq.com> on 2016/03/02 07:47:37 UTC

problem

Use POI on Android export word, use POI version 3.14, use is replaced in the template content to be derived, if the word template in the form of column number is less than or equal to 6 is replaced each column in the normal export of, if the form template is greater than 6 columns is derived from the word can not be opened, do not know what that is? You had encountered this problem? How to solve it.


code:
	public void writeDoc(File demoFile ,File newFile ,Map<String, String> map)
	{
		try
		{	
			FileInputStream in = new FileInputStream(demoFile);
			HWPFDocument hdt = new HWPFDocument(in);
			// Fields fields = hdt.getFields();
			// 读取word文本内容
			Range range = hdt.getRange();
			// System.out.println(range.text());
			
			// 替换文本内容
			for(Map.Entry<String, String> entry : map.entrySet())
			{
				range.replaceText(entry.getKey(), entry.getValue());
			}
			ByteArrayOutputStream ostream = new ByteArrayOutputStream();
			FileOutputStream out = new FileOutputStream(newFile, true);
			hdt.write(ostream);
			// 输出字节流
			out.write(ostream.toByteArray());
			out.close();
			ostream.close();
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}


template
         
绕组绝缘电阻(带平衡绕组)
         
高中压—低压平衡及地
         
高压—中低压及地
         
中压—高低压及地
         
低压—高中压及地
         
平衡—高中低压及地
         
高中压—低压及地
         
低压—高中压平衡及地
     
        
R15(MΩ)
         
063
         
064
         
065
         
066
         
067
         
068
         
069
     
        
R15(20℃) (MΩ)
         
070
         
071
         
072
         
073
         
074
         
075
         
076
     
        
R60(MΩ)
         
077
         
078
         
079
         
080
         
081
         
082
         
083
     
        
R60(20℃) (MΩ)
         
084
         
085
         
086
         
087
         
088
         
089
         
090
     
        
R600(MΩ)
         
091
         
092
         
093
         
094
         
095
         
096
         
097
     
        
R600(20℃) (MΩ)
         
098
         
099
         
100
         
101
         
102
         
103
         
104
     
        
吸收比
         
105
         
106
         
107
         
108
         
109
         
110
         
111
     
        
极化指数
         
112
         
113
         
114
         
115
         
116
         
117
         
118
     
        
试验仪器:119
   
仪器编号:120
     
        
项目结论:121