zoukankan      html  css  js  c++  java
  • EXCEL转html

            /*
    fullname:EXCEL全路径
    */

           Microsoft.Office.Interop.Excel.Application repExcel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = null; Microsoft.Office.Interop.Excel.Worksheet worksheet = null; //打开文件,n.FullPath是文件路径 workbook = repExcel.Application.Workbooks.Open(fullname, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1]; if (!Directory.Exists(System.IO.Path.Combine(System.IO.Directory.GetParent(fullname).FullName,"html"))) { // 创建up文件夹 Directory.CreateDirectory(System.IO.Path.Combine(System.IO.Directory.GetParent(fullname).FullName,"html")); } string ConfigPath = System.IO.Path.Combine(System.IO.Directory.GetParent(fullname).FullName, "html","a.html"); object savefilename = (object)ConfigPath; object ofmt = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml; //进行另存为操作 workbook.SaveAs(savefilename, ofmt, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); object osave = false; //逐步关闭所有使用的对象 workbook.Close(osave, Type.Missing, Type.Missing); repExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet); worksheet = null; //垃圾回收 GC.Collect(); System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook); workbook = null; GC.Collect(); System.Runtime.InteropServices.Marshal.ReleaseComObject(repExcel.Application.Workbooks); GC.Collect(); System.Runtime.InteropServices.Marshal.ReleaseComObject(repExcel); repExcel = null; GC.Collect(); //依据时间杀灭进程 System.Diagnostics.Process[] process = System.Diagnostics.Process.GetProcessesByName("EXCEL"); foreach (System.Diagnostics.Process p in process) { if (DateTime.Now.Second - p.StartTime.Second > 0 && DateTime.Now.Second - p.StartTime.Second < 5) { p.Kill(); } }
  • 相关阅读:
    selinux 设置的彻底理解 并要 熟练经常的使用
    关于linux下自定义的 alias文件和自定义函数库的通用写法(只适合自己的)
    linux下关于mysql的命令的用法
    彻底地/ 终于地, 解决 关于apache 权限的问题了:: 修改 DocumentRoot后的 403错误: have no permission to access / on this server
    php的内核组成模块和运行原理
    彻底了解 suid, sgid ,sticky权限
    php编程疑难解决-1
    再次安装fedora23的一些遗留问题的解决
    word如何替换行首?
    php高级开发参考地址
  • 原文地址:https://www.cnblogs.com/lucika/p/9723464.html
Copyright © 2011-2022 走看看