word转化为html

package word;

import java.io.File;

import jp.ne.so_net.ga2.no_ji.jcom.*;

public class TestWord {
	/**
	 * 删除文件
	 * @param fileName
	 * @return
	 */
	public static boolean deleteFile(String fileName) {
		File file = new File(fileName);
		if (file.isFile() && file.exists()) {

			file.delete();

			System.out.println("删除单个文件" + fileName + "成功!");
			return true;
		} else {
			System.out.println("删除单个文件" + fileName + "失败!");
			return false;
		}
	}
/**
 * 转化文件word为html
 * @param wordname
 * @param htmname
 */
	public static void changeWordToHtm(String wordname, String htmname) {

		

		ReleaseManager rm = new ReleaseManager();

		String userdir = System.getProperty("user.dir");

		String tempHtmlFile = userdir + "/" + htmname;
		System.out.println(tempHtmlFile);

		try {

			IDispatch wdApp = new IDispatch(rm, "Word.Application");

			wdApp.put("Visible", new Boolean(false));

			IDispatch wdDocuments = (IDispatch) wdApp.get("Documents");

			IDispatch wdDocument = (IDispatch) wdDocuments.method("Open",

			new Object[] { wordname });

			// 转换为HTML文件

			wdDocument.method("SaveAs", new Object[] { tempHtmlFile, 8 });

			wdApp.method("Quit", null);

			System.out.println("文件已经存放");
		

		} catch (Exception e) {

			e.printStackTrace();

		} finally {

			rm.release();
			System.out.println("释放完毕");

		}

	}

	public static void main(String[] args) {

		TestWord.changeWordToHtm("D:\\11.doc", "11.html");
		TestWord.deleteFile("D:/11.doc");

	}

}

 将jcom.dll放到jak的bin下面

你可能感兴趣的:(html,.net)