设为首页 | 加入收藏

欢迎访问彩票大赢家ios版下载-彩票大赢家开奖走势图大全-彩票大赢家双色球图表

活动预告 >> 彩票大赢家ios版下载-Excel文件转成html页面代码

Excel文件转成html页面代码

main类:发动类

package com.test; import trans.toHtml; public class testToHtml { /** * @param args */public static void main(String[] args) {// TODO Auto-generated method stub         toHtml th=new toHtml();        // System.out.println(System.getProperty("java.library.path"));         //-Djava.library.path=D:\jar\jacob_1.9         th.excelToHtml("d:/excel/运维门户通讯录.xlsx", "d:/test.html");} }

代码:

package trans; import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader; import com.jacob.activeX.ActiveXCompon全球进化ent;import com.jacob.com.Dispatch;import com.jacob.com.Variant; public class toHtml { int WORD_HTML = 8; int WORD_TXT = 7; int EXCEL_HTML = 44;  /**  * WORDHTML  * @param docfile WORD     * @param htmlfile     HTML      */ public void wordToHtml(String docfile, String htmlfile){  ActiveXComponent app = new ActiveXComponent("Word.Application"); //     word  try  {   app.setProperty("Visible", new Variant(false));   Dispatch docs = app.getProperty("Documents").toDispatch();   Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();   D彩票大赢家ios版下载-Excel文件转成html页面代码ispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant彩票大赢家ios版下载-Excel文件转成html页面代码(WORD_HTML) }, new int[1]);   Variant f = new Variant(false);   Dispatch.call(doc, "Close", f);  }  catch (Exception e)  {   e.printStackTrace();  }  finally  {   app.invoke("Quit", new Variant[] {});  } }  /**  * EXCELHTML  * @param xlsfile EXCEL     * @param htmlfile     HTML      */ public 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 彩票大赢家ios版下载-Excel文件转成html页面代码= 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]);   Variant f = new Variant(false);   Dispatch.call(excel, "Close", f);  }  catch (Exception e)  {   e.printStackTrace();  }  finally  {   app.invoke("Quit", new Variant[] {});  } }  /**  * /         * @param folderPath        * @param htmlfile     HTML      */  public void delFolder(String folderPath){      try      {         delAllFile(folderPath); //                        String filePath = folderPath;         filePath = filePath.toString();         java.io.File myFilePath = new java.io.File(filePath);         myFilePath.delete(); //            } catch (Exception e) {e.printStackTrace();} }  /** 彩票大赢家ios版下载-Excel文件转成html页面代码 * /                 * @param path      */ public boolean delAllFile(String path){        boolean flag = false;        File file = new File(path);        if (!file.exists())        {          return flag;        }        if (!file.isDirectory())        {          return flag;        }        String[] tempList = file.list();        File temp = null;        for (int i = 0; i < tempList.length; i++)        {           if (path.endsWith(File.separator))           {              temp = new File(path + tempList[i]);           }           else           {               temp = new File(path + File.separator + tempList[i]);           }           if (temp.isFile())           {              temp.delete();           }           if (temp.isDirectory())           {              delAllFile(path + "/" + tempList[i]);//                            delFolder(path + "/" + tempList[i]);//                      flag = true;           }        }        return flag;             }}需求的jar包<<jacob.jar>><<toHtml.java>><<testToHtml.java>>




上一条      下一条
返回顶部