huawei--在华为实现的excel转htm格式

package com.huawei.transfer;


import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class TransferAction {
public static final int WORD_HTML = 8;  
  public static final int WORD_TXT = 7;  
  public static final int EXCEL_HTML = 44;  
   
/**
* 格式为.htm,而不是.html
*/
public static void excelToHtml(String xlsfile, String htmlfile){  
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel  
try {  
app.setProperty("Visible", new Variant(false));  
Dispatch excels = app.getProperty("Workbooks").toDispatch();  
Dispatch excel = Dispatch.invoke(  
excels,  
"Open",  
Dispatch.Method,  
new Object[] { xlsfile, new Variant(false),  
new Variant(true) }, new int[1]).toDispatch();  
 
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {  
htmlfile, new Variant(EXCEL_HTML) }, new int[1]); //new Variant(44)一定是44
Variant f = new Variant(false);  
Dispatch.call(excel, "Close", f);  
}  
catch (Exception e){  
e.printStackTrace();  
}finally{  
app.invoke("Quit", new Variant[] {});  
}  
}  
 
 
public void deleteFolder(File dir) { 
File filelist[]=dir.listFiles(); 
int listlen=filelist.length; 
for(int i=0;i <listlen;i++) { 
if(filelist[i].isDirectory()) { 
deleteFolder(filelist[i]); 
filelist[i].delete();
}else{ 
filelist[i].delete(); 


}
 
public static void main(String[] args) {
File file1=new File("D:/report/");
File file2=new File("D:/report/html/");
if(!file1.exists()){file1.mkdir();}
if(!file2.exists()){file2.mkdir();}

Date d=new Date();
DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
String dateString=df.format(d);
System.out.println(dateString);


//文件格式为"SysInCall_2010-07-14.xls",所以该可执行文件要在报表订阅后执行(否则找不到);
String fromPath="D:/report/";
String fromFile="SysInCall_"+dateString+".xls";
 
 
String toPath="D:/report/html/";
String toFile="SysInCall.htm";
 
 
TransferAction ta=new TransferAction();
ta.deleteFolder(new File(toPath));
  ta.excelToHtml(fromPath+fromFile, toPath+toFile);

}
}

------------------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <!-- <script language="javascript" type="text/javascript" SRC="./PWD_IP.js" ></script>
  -->
  
  <script language='JavaScript' >  
  //获得本地IP地址
  function GetLocalIPAddress() { 
  var obj = null; 
  var rslt = ""; 
  try { 
  obj = new ActiveXObject("rcbdyctl.Setting"); 
  rslt = obj.GetIPAddress; 
  obj = null; 
  } catch(e){ 
  alert("some error is occuring!!");//异常发生 
  } 
  document.getElementById("LoginIP").value=rslt;
  } 
   
   
  //表单提交时验证密码
  function checkPassword(){
  var LoginIP=document.getElementById('LoginIP').value;
  var LoginPWD=document.getElementById('LoginPWD').value;
  //alert(LoginPWD.length);
  if(LoginPWD.length==0){
  return false;
  }
   
  var getPWD=getValue();
  if(trim(LoginPWD)==trim(getPWD)){
  return true;
  }
  return false;
  }
   
   
  //根据key值获得 文件中给定的value值
  function getValue(){
  var LoginIP=document.getElementById('LoginIP').value;
  var text=GetEverything();//读init.properties文件
  alert(text);
  var str =text.split(";");
  for(var i=0;i<str.length;i++){
  var location1=str[i].indexOf("=");
  var getIP=str[i].substr(0,location1);
  if(trim(LoginIP)==trim(getIP)){
  var len=str[i].length;
  var getPWD=str[i].substr(location1+1,len-1);
  alert("getPWD:"+getPWD);
  return getPWD;
  }
  }
  return; 
  }
  

//两端去空格函数 ,js中没有直接调用的trim方法
function trim(obj) { 
return obj.replace(/(^/s*)|(/s*$)/g, ""); 



//读init.properties文件
  function GetEverything() {  
  var fso;  
  var f;
  var ForReading = 1;
  var ForWriting = 2;  
  try { 
  fso = new ActiveXObject("Scripting.FileSystemObject");  
  var path=getPath();
  alert(path);
  //f = fso.OpenTextFile("E://workspace//reportProject//WebRoot//init.properties", ForReading);  
  f = fso.OpenTextFile(path, ForReading);  
  return f.ReadAll();
  } catch(e){ 
  alert("read file error");
  return false;
  }
  } 
   
   
  //获得文件路径
  function getPath(){
  alert(document.location.href);
  var pathfile=document.location.href;
  var path=pathfile.substr(8,pathfile.length-18);
  return path+"init.properties";
  }
   
   
  </script>
   
   
  <style>
body{
padding:0;
margin:0:
}

.bodier{
margin:0 auto;
width:1003px;
height:759px;
background:url(backgr.gif) no-repeat;
}
.login{
width:482px;
margin:350px 0px 0px 279px;
}
</style>
  </head>
 
 
  
  <body>  
  <div class="bodier">
<div class="login" align="center">
 
AdressIP :<input type="text" name="LoginIP" id="LoginIP" disabled/><br/>
  <form id="loginForm" name="loginForm" method="post" onSubmit="return checkPassword();" 
  action="report1.html"> 
  Password :<input type="password" name="LoginPWD" id="LoginPWD"/><br/><br/>
  <input type="reset" name="reset" value="reset"/>
  <input type="submit" name='submit' value="submit"/>
  </form>
 
 
 
</div>
  </div>
  
  
  
  
  <script>
  GetLocalIPAddress();
  </script>
  </body>
 
 
  
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值