怎么把string写入word文档中?
public static void main(String[] args) {// TODO Auto-generated method stubString fileName = "a doc file";File f = new File("e:\\" + fileName + ".doc");OutputStream out = null;try {out = new FileOutputStream(f);} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();}String name = "mike";try {out.write(name.getBytes());out.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}
如何将Microsoft todo放到电脑桌面
there is no doubt 后面不可以跟to do 或doing,其固定用法如下:1.There is no doubt that ...,即后面接that子句,如:There is no doubt that she will keep her word.毫无疑问她会遵守诺言的.2.There is no doubt about sth.There is no doubt about his innocence.他完全是无辜的。
3.There is no doubt with sth.There is no doubt with his faithness.他的忠诚无可置疑。
4.There is no doubt as to ...There is no doubt as to what he said.有关他所说的话是不容置疑的。
5.There is no doubt of sth.There is no doubt of it.毫无疑问。
6.There is no doubt in ...There is no doubt in his honesty.他的诚实是无庸置疑的。
7.单独作插入语,如:"There is no doubt, he is out.“毫无疑问,他被排除了。
”
..."m"intheword"muscle".Thereismuchhomework
这个说不好的 要靠积累 给你个参考:一、动词+介词to+动名词1.admit to doing sth 承认做了某事 2.apply to doing sth 适用于做某事 3.object to doing sth 反对做某事 4.see to doing sth 负责做某事 5.stick to doing sth 坚持做某事 6.take to doing sth 喜欢上做某事,逐渐习惯做某事 应用实例:He admitted having stolen the money.他承认偷了钱.These methods apply to learning English.这些方法适用于英语学习.He objected to being treated like a child.他反对被当作小孩子看待.Reporters should stick to investigating the facts.记者应坚持调查事实.Soon he took to sleeping late.不久他就养成了睡懒觉的习惯.二、动词+宾语+介词to+动名词7.apply oneself to doing sth 专心致力于做某事 8.devote sth to doing sth 把……献给做某事 9.devote oneself to doing sth 献身于做某事 10.limit sth to doing sth 把…限制在做某事的范围内 11.reduce sb to doing sth 使某人沦为做某事 12.give one's life to doing sth 献身于做某事 13.give one's mind to doing sth 专心做某事 14.have a dislike to doing sth 厌恶做某事 15.have an eye to doing sth 注意做某事 16.have an objection to doing sth 反对(反感)做某事 17.pay attention to doing sth 注意做某事 18.set one's mind to doing sth 决心做某事 应用实例:She applied herself to learning English.她专心学习英语.Hunger reduced them to stealing.饥饿使他们沦落为盗贼.She devoted herself to helping the poor.她致力于帮助穷人.I have a strong dislike to playing cards for money.我极讨厌打牌赌博.He has a strong objection to getting up so early.他很反感这么早就起床.You should pay more attention to uniting and working with those who differ with you.你应该更注意团结那些自己意见不同的人一道工作.三、be+形容词(含过去分词)+介词to+动名词19.be equal to doing sth 等于做某事,能胜任做某事 20.be used to doing sth 习惯于做某事 21.be opposed to doing sth 反对做某事 22.be reduced to doing sth使某人沦为做某事 23.be devoted to doing sth 把时间(钱,精力等)献给做某事 24.be limited to doing sth把……限制在做某事的范围内 应用实例:This is equal to saying that he's a cheat.这就等于说他是个骗子.She is used to living in the country.她习惯于住在乡下.I'm opposed to telling him the news at once.我反对马上告诉他这消息.This dictionary is devoted to explaining word usage.这本词典是解释词的用法的.四、其他结构+介词to+动名词25.get down to doing sth开始做某事,认真处理某事 26.look forward to doing sth 盼望做某事 27.What do you say to doing sth?你认为做某事如何?应用实例:We are looking forward to receiving his letter.我们盼望收到他的回信.It's time we got down to some serious work.我们该认真干点正事了.What do you say to having a glass of beer?喝杯啤酒如何?
java poi 操作word文档,怎么写入带上下标的文字?
步骤第一步,使用输入流打开文件,并获得文档的XWPFDocument对象。
然后获得文档的所有段落,进而获得要操作的文本框所在的段落,具体使用时候,可以通过判断或者print操作得知要操作的文本框到底是哪一段。
FileInputStream fis = newFileInputStream("e:/file.docx");XWPFDocument doc = new XWPFDocument(fis);List paragraphList =doc.getParagraphs();XWPFParagraph paragraph = paragraphList.get(10);文本框在Word中显示第二步,获取XWPFParagraph的XmlObject,然后获得XmlObject对象的游标。
可以通过打印XmlObject来得知当前XML的内容,也可以使用XmlCursor的getName方法和getTextValue方法来查看当前游标所在位置的Node及Node的值。
XmlObject object =paragraph.getCTP().getRArray(1);XmlCursor cursor = object.newCursor();第四步,通过移动游标,找到要修改的文本所在位置,然后使用游标的setTextValue来设置其值。
//修改第一处文本:cursor.toChild(1); cursor.toChild(0);cursor.toChild(3); cursor.toChild(0); cursor.toChild(0); cursor.toChild(3);cursor.toChild(1); cursor.setTextValue("First");// 修改第二处文本cursor.toParent(); cursor.toParent();cursor.toChild(1);cursor.toChild(3); cursor.toChild(1);cursor.setTextValue("Second");第四步,保存文件、关闭输入输出流。
FileOutputStream fos = newFileOutputStream("e:/export.docx");doc.write(fos);fos.flush();fos.close();fis.close();修改后的文本框
java poi模板导出word后用微软的word打不开,但是wps可以,跪求大...
楼主你好,首先你检测一下你的word是否正常,方法是:点开始,再点运行,输入winword /safe(注意,/前面有一个空格),看看是否能打开word,如果可以,那么word是正常的,没有问题。
那么楼主打不开word可能是通用模板的问题了,通用模板的具体路径为:C:\Documents and Settings\Administrator\Application Data\Microsoft\Templates,把这个文件夹下的内容全部彻底删除,然后再去打开word,它会自动生成一个默认的通用模板,问题应该就能解决了!
java解析word文档有哪些方法
展开全部 java读取word文档时,虽然网上介绍了很多插件poi、java2Word、jacob、itext等等,poi无法读取格式(新的API估计行好像还在处于研发阶段,不太稳定,做项目不太敢用);java2Word、jacob容易报错找不到注册,比较诡异,我曾经在不同的机器上试过,操作方法完全一致,有的机器不报错,有的报错,去他们论坛找高人解决也说不出原因,项目部署用它有点玄;itxt好像写很方便但是我查了好久资料没有见到过关于读的好办法。
经过一番选择还是折中点采用rtf最好,毕竟rtf是开源格式,不需要借助任何插件,只需基本IO操作外加编码转换即可。
rtf格式文件表面看来和doc没啥区别,都可以用word打开,各种格式都可以设定。
----- 实现的功能:读取rtf模板内容(格式和文本内容),替换变化部分,形成新的rtf文档。
----- 实现思路:模板中固定部分手动输入,变化的部分用$info$表示,只需替换$info$即可。
1、采用字节的形式读取rtf模板内容2、将可变的内容字符串转为rtf编码3、替换原文中的可变部分,形成新的rtf文档主要程序如下:public String bin2hex(String bin) {char[] digital = "0123456789ABCDEF".toCharArray();StringBuffer sb = new StringBuffer("");byte[] bs = bin.getBytes();int bit;for (int i = 0; i > 4;sb.append("\\'");sb.append(digital[bit]);bit = bs[i] & 0x0f;sb.append(digital[bit]);}return sb.toString(); }public String readByteRtf(InputStream ins, String path){ String sourcecontent =""; try{ ins = newFileInputStream(path); byte[] b= new byte[1024];if (ins == null) {System.out.println("源模板文件不存在");}int bytesRead = 0;while (true) {bytesRead = ins.read(b, 0, 1024); // return final read bytescountsif(bytesRead == -1) {// end of InputStreamSystem.out.println("读取模板文件结束");break;}sourcecontent += new String(b, 0, bytesRead); // convert to stringusing bytes} }catch(Exception e){ e.printStackTrace(); } return sourcecontent ;}以上为核心代码,剩余部分就是替换,从新组装java中的String.replace(oldstr,newstr);方法可以实现,在这就不贴了。
源代码部分详见附件。
运行源代码前提:c盘创建YQ目录,将附件中"模板.rtf"复制到YQ目录之下,运行OpreatorRTF.java文件即可,就会在YQ目录下生成文件名如:21时15分19秒_cheney_记录.rtf的文件。
package com;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import java.text.SimpleDateFormat;import java.util.Date;public class OperatorRTF {public String strToRtf(String content){char[] digital = "0123456789ABCDEF".toCharArray();StringBuffer sb = new StringBuffer("");byte[] bs = content.getBytes();int bit;for (int i = 0; i > 4;sb.append("\\'");sb.append(digital[bit]);bit = bs[i] & 0x0f;sb.append(digital[bit]);}return sb.toString();}public String replaceRTF(String content,String replacecontent,intflag){String rc = strToRtf(replacecontent);String target = "";if(flag==0){target = content.replace("$timetop$",rc);}if(flag==1){target = content.replace("$info$",rc);}if(flag==2){target = content.replace("$idea$",rc);}if(flag==3){target = content.replace("$advice$",rc);}if(flag==4){target = content.replace("$infosend$",rc);}return target;}public String getSavePath() {String path = "C:\\YQ";File fDirecotry = new File(path);if (!fDirecotry.exists()) {fDirecotry.mkdirs();}return path;}public String ToSBC(String input){char[] c =input.toCharArray();for (int i =0; i < c.length; i++){if (c[i] == 32){c[i] = (char) 12288;continue;}if (c[i] < 127){c[i] = (char) (c[i] + 65248);}}return newString(c);}public void rgModel(String username, String content) {// TODO Auto-generated method stubDate current=new Date();SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-ddHH:mm:ss");String targetname = sdf.format(current).substring(11,13) + "时";targetname += sdf.format(current).substring(14,16) + "分";targetname += sdf.format(current).substring(17,19) + "秒";targetname += "_" + username +"_记录.rtf";String strpath = getSavePath();String sourname = strpath+"\\"+"模板.rtf";String sourcecontent = "";InputStream ins = null;try{ins = new FileInputStream(sourname);byte[] b = new byte[1024];if (ins == null) {System.out.println("源模板文件不存在");}int bytesRead = 0;while (true) {bytesRead = ins.read(b, 0, 1024); // return final read bytescountsif(bytesRead == -1) {// end of InputStreamSystem.out.println("读取模板文件结束");break;}sourcecontent += ...
飞扬的小胖子