甘之如饴,王者荣耀李白,喜上眉头-有爱俱乐部,让爱心充满这个世界

admin 1个月前 ( 07-18 07:54 ) 0条评论
摘要: Excel文件转成html页面代码main类:启动类package com.test; import trans.toHtml; public class testToHtml {...

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.pk1387rintln(System.getProperty("java.library.path"));         //-Djava.library.path=D:\jar\jatvs3在线直播cob_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.FileIn亲吻妈妈putStream;import j陈诺仪ava.io.FileNotFoundE百战经典名将与名战xception;import java.io.FileWriter;import java.io.IOExceptio百战经典名将与名战n;import java.io.InputStreamReader; import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch;import com.jacob.com.Variant; public class toHtml { int WORD_HTML = 8; int WORD_TX甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际T = 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.gtoptoon漫画etProperty("Documents").toDispatch();   Dispatch doc = Dispatch.invoke(docs,"Open",D天津平行进口车命案ispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();   Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);   Var白启娴iant f = new Variant(false);   Dispatch.call(doc, "Close", f);  }  catch (Exception e)  {   e.printStackTrace();  }  finall甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际y  {   app.invoke("Quit", new Variant[] {});  } }  /**  * EXCELHTML  * @param xlsfile EXCEL     * @param htmlfile     HTML      */ public void excelToHtml(String xlsfile, String htmlfile){  ActiveXComponent app = n飞笛智投ew ActiveXComponent("Exce绿野易购l.Application"); //     excel  try  {   app.setPropert甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际y("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]);   Variant f = new Variant(false);   Dispatch.call(exce暗夜恩惠录l甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际, "Close", f);  }  catch (Exception e)  {   e.printStackTrace();  }  finally  {   app.invoke("Quit", new Variant[] {});  } }  /**  * /         * @param folderP甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际ath        * @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();} }  /**  * /                 * @param path      */ public boolean delAllFile(String path){        boolean flag = false;        File file = new File(path);        if (!file.exists())        {          return flag;        }        if (!file.isDirectory())        {          retu常永芬rnbibijones 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())           {              d甘之如饴,王者荣耀李白,喜上眉头-有爱沙龙,让爱心充溢这个国际elAllFile(path + "/" + tempList[i]);//                            delFolder(path + "/" 崔铁飞+ tempList[i]);//                      flag = true;           }        }        return flag;             }}需求的jar包<<jacob.jar>><<toHtml.java>><<testToHtm夏仁珍l.java>>


文章版权及转载声明:

作者:admin本文地址:http://lovecub50.com/articles/2519.html发布于 1个月前 ( 07-18 07:54 )
文章转载或复制请以超链接形式并注明出处有爱俱乐部,让爱心充满这个世界