java mysql 获取页码,java获取word页数

1.java 要怎么准确获取word的总页数

XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(电月度例会会议纪要.docx));

int pages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();//总页数

int wordCount = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters();// 忽略空格的总字符数 另外还有getCharactersWithSpaces()方法获取带空格的总字数。

System.out.println (pages= + pages + wordCount= + wordCount);}

public static void parse97() throws Exception {

WordExtractor doc = new WordExtractor(new FileInputStream(电月度例会会议纪要.doc));

2.java如何获取word文档页数

XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(电月度例会会议纪要.docx)); int pages = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();//总页数 int wordCount = docx.getProperties().getExtendedProperties().getUnderlyingProperties().getCharacters();// 忽略空格的总字符数 另外还有getCharactersWithSpaces()方法获取带空格的总字数。

System.out.println (pages= + pages + wordCount= + wordCount);} public static void parse97() throws Exception { WordExtractor doc = new WordExtractor(new FileInputStream(电月度例会会议纪要.doc));。

3.Java中如何获取PDF文件的总页数

用Free Spire.PDF JAVA版本import com.spire.pdf.PdfDocument;import com.spire.pdf.PdfPageBase;import java.io.*;public class CountPages{public static void main(String[] args) {//创建PdfDocument实例PdfDocument doc=new PdfDocument();//加载PDF文件doc.loadFromFile("test.pdf"); int pageCount = doc.getPages().getCount(); doc.close();}}。

4.java实现插入word页眉页脚以及生成目录及页码

public class JavaToWords {

/**

* word运行程序对象

*/

private ActiveXComponent word;

/**

* 选定内容

* @return Dispatch 选定的范围或插入点

*/

public Dispatch select() {

return word.getProperty("Selection").toDispatch();

}

public void toWord(String seekView) {

Dispatch selection = select();

//设置页眉

if(seekView != null && !"".equals(seekView)){

//取得活动窗体对象

Dispatch ActiveWindow = word.getProperty("ActiveWindow").toDispatch();

//取得活动窗格对象

Dispatch ActivePane = Dispatch.get(ActiveWindow,"ActivePane").toDispatch();

//取得视窗对象

Dispatch View = Dispatch.get(ActivePane, "View").toDispatch();

try{

Dispatch.put(View,"SeekView", "9"); //设置页眉

Dispatch.put(selection,"Text",seekView);

Dispatch.put(View, "SeekView", "10"); // 10是设置页脚

Dispatch.put(selection, "Text", seekView); //

}finally{

if(ActiveWindow != null ) ActiveWindow.safeRelease();

if(ActivePane != null ) ActivePane.safeRelease();

if(View != null ) View.safeRelease();

}

}

}

}

希望对你有些帮助,不过好像要下一个外部资源包,叫jacob 的,我也记的不太清楚了,应该是这个,你找找看

5.Java读取数据库打印到word文档问题求教各位大侠,java写

为什么非要写道word文档中? 你可以写进txt文件中,然后使用word进行编辑 如果确实需要,请看下面的例子: import java。

io。File; import java。

io。FileInputStream; import java。

io。FileOutputStream; import org。

apache。poi。

hwpf。extractor。

WordExtractor; import org。apache。

poi。hwpf。

model。io。

HWPFOutputStream; public class Word { /** * 读取纯文本的word文件 */ public String readWord(String doc) throws Exception { String context = null; WordExtractor extractor = null; //纯文本的遍历器 try { FileInputStream in = new FileInputStream(new File(doc)); extractor = new WordExtractor(in); context = extractor。 getText(); } catch (Exception e) { e。

printStackTrace(); } return context; } /** * 对word文档做写操作 * */ public boolean writeWord(String path, String content) throws Exception { boolean w = false; try { byte b[] = content。 getBytes(); FileOutputStream fs = new FileOutputStream(path); HWPFOutputStream hos = new HWPFOutputStream(); hos。

write(b, 0, b。length); hos。

writeTo(fs); hos。close(); w=true; } catch (Exception e) { e。

printStackTrace(); } return w; } public static void main(String[] args) { ReadWord rw = new ReadWord(); try{ String text = rw。 readDoc("D:\\workspace\\MyUntil\\t。

doc"); rw。writeDoc("D:\\workspace\\MyUntil\\d。

doc", text); }catch(Exception e){ e。 printStackTrace(); } } } 所需的包请各位自己上apache的官网上poi工程目录下下吧 poi-3。

5-final poi-contrib-3。5-final poi-ooxml-3。

5-final poi-scratchpad-3。5-final 。

6.java实现插入word页眉页脚以及生成目录及页码

public class JavaToWords { /** * word运行程序对象 */ private ActiveXComponent word; /** * 选定内容 * @return Dispatch 选定的范围或插入点 */ public Dispatch select() { return word.getProperty("Selection").toDispatch(); }public void toWord(String seekView) {Dispatch selection = select();//设置页眉if(seekView != null && !"".equals(seekView)){//取得活动窗体对象 Dispatch ActiveWindow = word.getProperty("ActiveWindow").toDispatch(); //取得活动窗格对象 Dispatch ActivePane = Dispatch.get(ActiveWindow,"ActivePane").toDispatch(); //取得视窗对象 Dispatch View = Dispatch.get(ActivePane, "View").toDispatch(); try{ Dispatch.put(View,"SeekView", "9"); //设置页眉 Dispatch.put(selection,"Text",seekView); Dispatch.put(View, "SeekView", "10"); // 10是设置页脚Dispatch.put(selection, "Text", seekView); // }finally{if(ActiveWindow != null ) ActiveWindow.safeRelease();if(ActivePane != null ) ActivePane.safeRelease();if(View != null ) View.safeRelease();}}}}希望对你有些帮助,不过好像要下一个外部资源包,叫jacob 的,我也记的不太清楚了,应该是这个,你找找看。

7.使用java读取word文档中的内容

使用流就可以读呀

String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));

FileInputStream fis = null; FileOutputStream fos = null;

fis = new FileInputStream("e:/topo.svg"); fos = new FileOutputStream("e:/a.txt");

BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fis));

StringBuffer sb = new StringBuffer();

String str = null;

while ((str = bufferReader.readLine()) != null) {

sb.append(str + lineSeparator);

}

OutputStreamWriter writer = new OutputStreamWriter(fos);

writer.write(sb.toString());

writer.flush();

writer.close();

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值