「java连接wps」java连接数据库的四种方式

博主:adminadmin 2023-01-27 03:27:10 573

本篇文章给大家谈谈java连接wps,以及java连接数据库的四种方式对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

请教,怎么在JAVA程序中调用WPS个人版

可以的,但是构造方法的引用必须写在当前构造函数的第一句:this();//有参数的要写参数。

用java调用wps时打开一个txt文档,每次都有个文件转换的提示框

谈论个人的经验。我也遇到过这个问题,我的字是完整的安装,但该系统是GHOST。网上说的方式做了一圈,始终是不!最后,解决的办法是下载一个绿色的的WPS2010使用它来打开该文件,重新保存为WORD文件。 ......

所以,做剧烈的折腾它,或得到的绿色精简版WPS,DOC造成的。

java能否wps调用页码

1. [代码][Java]代码

package experiments;

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.DispatchEvents;

import com.jacob.com.Variant;

import java.io.File;

import java.util.logging.Level;

import java.util.logging.Logger;

public class Doc2Pdf {

public static Converter newConverter(String name) {

if (name.equals("wps")) {

return new Wps();

} else if (name.equals("pdfcreator")) {

return new PdfCreator();

}

return null;

}

public synchronized static boolean convert(String word, String pdf) {

return newConverter("pdfcreator").convert(word, pdf);

}

public static interface Converter {

public boolean convert(String word, String pdf);

}

public static class Wps implements Converter {

public synchronized boolean convert(String word, String pdf) {

File pdfFile = new File(pdf);

File wordFile = new File(word);

ActiveXComponent wps = null;

try {

wps = new ActiveXComponent("wps.application");

ActiveXComponent doc = wps.invokeGetComponent("Documents").invokeGetComponent("Open", new Variant(wordFile.getAbsolutePath()));

doc.invoke("ExportPdf", new Variant(pdfFile.getAbsolutePath()));

doc.invoke("Close");

doc.safeRelease();

} catch (Exception ex) {

Logger.getLogger(Doc2Pdf.class.getName()).log(Level.SEVERE, null, ex);

return false;

} catch (Error ex) {

Logger.getLogger(Doc2Pdf.class.getName()).log(Level.SEVERE, null, ex);

return false;

} finally {

if (wps != null) {

wps.invoke("Terminate");

wps.safeRelease();

}

}

return true;

}

}

public static class PdfCreator implements Converter {

public static final int STATUS_IN_PROGRESS = 2;

public static final int STATUS_WITH_ERRORS = 1;

public static final int STATUS_READY = 0;

private ActiveXComponent pdfCreator;

private DispatchEvents dispatcher;

private volatile int status;

private Variant defaultPrinter;

private void init() {

pdfCreator = new ActiveXComponent("PDFCreator.clsPDFCreator");

dispatcher = new DispatchEvents(pdfCreator, this);

pdfCreator.setProperty("cVisible", new Variant(false));

pdfCreator.invoke("cStart", new Variant[]{new Variant("/NoProcessingAtStartup"), new Variant(true)});

setCOption("UseAutosave", 1);

setCOption("UseAutosaveDirectory", 1);

setCOption("AutosaveFormat", 0); // 0 = PDF

defaultPrinter = pdfCreator.getProperty("cDefaultPrinter");

status = STATUS_IN_PROGRESS;

pdfCreator.setProperty("cDefaultprinter", "PDFCreator");

pdfCreator.invoke("cClearCache");

pdfCreator.setProperty("cPrinterStop", false);

}

private void setCOption(String property, Object value) {

Dispatch.invoke(pdfCreator, "cOption", Dispatch.Put, new Object[]{property, value}, new int[2]);

}

private void close() {

if (pdfCreator != null) {

pdfCreator.setProperty("cDefaultprinter", defaultPrinter);

pdfCreator.invoke("cClearCache");

pdfCreator.setProperty("cPrinterStop", true);

pdfCreator.invoke("cClose");

pdfCreator.safeRelease();

pdfCreator = null;

}

if (dispatcher != null) {

dispatcher.safeRelease();

dispatcher = null;

}

}

public synchronized boolean convert(String word, String pdf) {

File pdfFile = new File(pdf);

File wordFile = new File(word);

try {

init();

setCOption("AutosaveDirectory", pdfFile.getParentFile().getAbsolutePath());

if (pdfFile.exists()) {

pdfFile.delete();

}

pdfCreator.invoke("cPrintfile", wordFile.getAbsolutePath());

int seconds = 0;

while (isInProcess()) {

seconds++;

if (seconds 30) { // timeout

throw new Exception("convertion timeout!");

}

Thread.sleep(1000);

}

if (isWithErrors()) return false;

// 由于转换前设置cOption的AutosaveFilename不能保证输出的文件名与设置的相同(pdfcreator会加入/修改后缀名)

// 所以这里让pdfcreator使用自动生成的文件名进行输出,然后在保存后将其重命名为目标文件名

File outputFile = new File(pdfCreator.getPropertyAsString("cOutputFilename"));

if (outputFile.exists()) {

outputFile.renameTo(pdfFile);

}

} catch (InterruptedException ex) {

Logger.getLogger(Doc2Pdf.class.getName()).log(Level.SEVERE, null, ex);

return false;

} catch (Exception ex) {

Logger.getLogger(Doc2Pdf.class.getName()).log(Level.SEVERE, null, ex);

return false;

} catch (Error ex) {

Logger.getLogger(Doc2Pdf.class.getName()).log(Level.SEVERE, null, ex);

return false;

} finally {

close();

}

return true;

}

private boolean isInProcess() {

return status == STATUS_IN_PROGRESS;

}

private boolean isWithErrors() {

return status == STATUS_WITH_ERRORS;

}

// eReady event

public void eReady(Variant[] args) {

status = STATUS_READY;

}

// eError event

public void eError(Variant[] args) {

status = STATUS_WITH_ERRORS;

}

}

public static void main(String[] args) {

convert("e:\\test.doc", "e:\\output.pdf");

}

}

用java将数据导出到wps表格中,怎么实现

方法一、 粘贴到记事本 数据——导入数据,身份证列设为文本格式 。 方法二、 WPS表格中,身份证对应列设为文本格式。 选择性粘贴,无格式文本

您好,我想用java代码调用wps?

代码方法如下,从流加载wps文件,转为pdf格式

import com.spire.doc.*;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

public class WordToPDF {

public static void main(String[] args)throws IOException {

FileInputStream inputStream = new FileInputStream(new File("test.wps"));

Document document = new Document();

document.loadFromStream(inputStream, FileFormat.Doc);

document.saveToFile("WPStoPDF.pdf",FileFormat.PDF);

}

}

在程序中需引入 spire.doc.jar。

java连接wps的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java连接数据库的四种方式、java连接wps的信息别忘了在本站进行查找喔。