关闭

用Javascript与WScript实现PPT->HTM在线转换,压缩并上传

1571人阅读 评论(0) 收藏 举报

 


<%@ page language="java" contentType="text/html;charset=GBK"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="http://localhost:8080/web1/">
   
    <title>My JSP 'MyJsp.jsp' starting page</title>
   
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
   
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

 <SCRIPT LANGUAGE="JavaScript">
 <!--

 var target_htm_name = "test";


 var target_htm_folder = "c://temp//tchaid//uptmp//" + target_htm_name;
 var target_htm_file = target_htm_folder + "//" + target_htm_name + ".htm";
 var target_rar_file = target_htm_folder + "//" + target_htm_name + ".rar";

 function check_folder()
 {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  if(!fso.FolderExists("c://temp"))
   fso.CreateFolder("c://temp");

  if(!fso.FolderExists("c://temp//tchaid"))
   fso.CreateFolder("c://temp//tchaid");

  if(!fso.FolderExists("c://temp//tchaid//uptmp"))
   fso.CreateFolder("c://temp//tchaid//uptmp");

  if(!fso.FolderExists(target_htm_folder))
   fso.CreateFolder(target_htm_folder);
 }

 function ConvertPPT2MHT(file)
 {
  var PPT = new ActiveXObject("PowerPoint.Application");
  var Pres = PPT.Presentations.Open(file, false, false, false);
  Pres.SaveAs(target_htm_file, 12, false);
  Pres.Close();
 }
 
 function Compress()
 { 
  var winRar=new ActiveXObject("WScript.Shell");  
  var tmp = winRar.CurrentDirectory;
  winRar.CurrentDirectory = target_htm_folder;
  var cmd="winrar a "+ target_rar_file + " . -r" ;
  winRar.run(cmd,1,true);
  winRar.CurrentDirectory = tmp;
 

  var fso = new ActiveXObject("Scripting.FileSystemObject");
  fso.DeleteFile(target_htm_file,true);

  var t = target_htm_folder + "//" + target_htm_name + ".files";
  fso.DeleteFolder (t,true);

  winRar.SendKeys("^a");
  winRar.SendKeys(target_rar_file);
  winRar = null;
 }
 
 function do_upload()
  {
   var form = document.forms["myform"];
   if(form.sFile.value == target_rar_file)
    form.submit();
   else
    setTimeout('do_upload()',10); //由于消息机制,winRar.SendKeys的按键消息此时还没有生效,这里用
  }                                                       //定时器来给系统一个机会来在提交之前把按键消息处理完
 
 function on_upload(form)
 {
  var form = document.forms["myform"];
 
  if(form.sFile.value.length == 0)
  {
   alert("你没有选择任何文件,请选择要上传的PPT或DOC文件!");
   return false ;
  }

  var type = 0 ;
  if(/ppt$/i.test(form.sFile.value)) 
   type = 1 ;       //PPT文件
  else if(/doc$/i.test(form.sFile.value))
   type = 2 ;       //DOC文件
 
  if(type == 0)
  {
   alert("请选择PPT文件或DOC文件上传!");
   return false ;
  }

  form.sFile.focus();
  check_folder();
  ConvertPPT2MHT(form.sFile.value);
  Compress();

 do_upload();
 }
 
  
  
 

 //-->
 </SCRIPT>
  </head>
 
  <body>
   
    Select a PPT file
 <form name="myform" action="upload_handler.jsp" method="post" enctype="multipart/form-data">
  <input type="file" name="sFile" id="sFile" />
  <input type="button" name="Button" value="upload" onclick="on_upload()"/>
  <input type="submit" name="Button" value="submit"/>
 </form>
   
  </body>
</html>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:94755次
    • 积分:1408
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:0篇
    • 译文:0篇
    • 评论:27条
    文章分类
    最新评论