日期:2014-05-17  浏览次数:20740 次

接手的第一个小项目,请教各位达人。。。
刚从学校出来工作,现在头儿给我分配一个任务,大概是这样的:
可以在web页面生成word文档,上传到数据库
然后还可以从数据库读取word文档生成html在web页面上显示
用Java或PHP实现
越详细越好,如果有人愿意教我感激不尽

可能对于大家不算什么,但对于我还是蛮困难的,第一个小项目力争做好
没多少分,但已经是我全部的家当了

------解决方案--------------------
1,web页面生成word文档: 用Itext插件吧 现成的 直接用 如果不会用 去网上看个例子 照猫画虎总会吧
2,上传到数据库: 有个疑问,是将word文档中的数据保存到数据库,还是将整个文档上传到数据库?
如果是前者,那把数据读出来,直接用个insert 语句将数据插入 数据库就行 如果是后者 用个SimpleUpLoad插件吧 同上!
3,从数据库读取word文档生成html在web页面上显示 将数据读出来 select 显示到页面上 应该不难吧~


good luck~



------解决方案--------------------
公司封QQ,
给你贴一部分代码吧

使用的插件是:flexpaper

1.上传pdf文档,并转换为swf格式的(转换为了swf格式的在查看的时候才可以直接类似于豆丁啊,百度文库之类的播放)

private String finishAttachment(Attachment attachment,
Institution institution){
String info = "";
File[] files = attachment.getFile();
String path = ServletActionContext.getServletContext().getRealPath(
"data/regulations");
File desc = new File(path);
if (!desc.exists()) {
desc.mkdir();
}
for (int i = 0; i < files.length; i++) {
File file = files[i];
long now = System.currentTimeMillis();
String fileName = attachment.getFileFileName()[i];
path += File.separator + now + "_" + fileName;
institution.setUrl(now + "_" + fileName);
saveFile(file, path);
try {
PDF2SWFUtil.pdf2swf(path, Const.EXE_PATH);
} catch (IOException e) {
e.printStackTrace();
}

}
return info;
}


2.工具类:
package com.eimone.institution.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class PDF2SWFUtil {
/**
* 利用SWFTools工具将pdf转换成swf,转换完后的swf文件与pdf同名

* @author iori
* @param fileDir
* PDF文件存放路径(包括文件名)
* @param exePath
* 转换器安装路径
* @throws IOException
*/
public static synchronized void pdf2swf(String fileDir, String exePath)
throws IOException {
// 文件路径
String filePath = fileDir.substring(0, fileDir.lastIndexOf(File.separator));
// 文件名,不带后缀
String fileName = fileDir.substring((filePath.length() + 1), fileDir
.lastIndexOf("."));
String fileNewName = fileName.substring(0, fileName.indexOf("_"));
Process pro = null;
if (isWindowsSystem()) {
// 如果是windows系统
// 命令行命令
String cmd = exePath + " \"" + fileDir + "\" -o \"" + filePath
+ File.separator + fileNewName + ".swf\"" + " -T 9";
// Runtime执行后返回创建的进程对象
pro = Runtime.getRuntime().exec(cmd);
} else {
// 如果是linux系统,路径不能有空格,而且一定不能用双引号,否则无法创建进程
String[] cmd = new String[3];
cmd[0] = exePath;
cmd[1] = fileDir;
cmd[2] = filePath + File.separator + fileNewName + ".swf";
// Runtime执行后返回创建的进程对象
pro = Runtime.getRuntime().exec(cmd);
}
// 非要读取一遍cmd的输出,要不不会flush生成文件(多线程)
new DoOutput(pro.getInputStream()).start();
new DoOutput(pro.getErrorStream()).start();
try {
// 调用waitFor方法,是为了阻塞当前进程,直到cmd执行完
pro.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

/**
* 判断是否是windows操作系统

* @author iori
* @return
*/
private static boolean isWindowsSystem() {
String