.net C# COM组件,实现EXCEL自动转换格式与如何退出EXCEL Process
来源:互联网 发布:js控制input焦点 编辑:程序博客网 时间:2024/05/16 08:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;
using Microsoft.Office.Interop.Excel;
namespace Report
{
[Guid("7F77CA9F-41DC-4161-AC94-7349FDCC5C28")]
public interface Ireport
{
[DispId(1)]
void ReportrstjToHtm();
[DispId(2)]
void ReportrshzToHtm();
[DispId(3)]
void ReportxcfxToHtm();
}
[Guid("47C976E0-C208-4740-AC42-41212D3C34F0"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Ereport
{
}
[Guid("3948822C-9D6A-454e-820E-D5119898E900"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(Ereport))]
public class Report : Ireport
{
public Report()
{
}
public void ReportrstjToHtm()
{
DateTime startTime = DateTime.Now;
Microsoft.Office.Interop.Excel.Application excelapp = new Microsoft.Office.Interop.Excel.ApplicationClass();
excelapp.Application.DisplayAlerts = false;
excelapp.Application.Workbooks.Open("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\rstjbb.xlsx",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value
);
excelapp.Application.ActiveWorkbook.SaveAs("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\rstjbb.aspx", Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml, Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
excelapp.Application.Workbooks.Close();
excelapp.Application.Quit();
excelapp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp);
DateTime endTime = DateTime.Now;
killProcess(startTime, endTime, "EXCEL");
GC.Collect(); //回收垃圾
}
public void ReportrshzToHtm()
{
DateTime startTime = DateTime.Now;
Microsoft.Office.Interop.Excel.Application excelapp1 = new Microsoft.Office.Interop.Excel.ApplicationClass();
excelapp1.Application.DisplayAlerts = false;
excelapp1.Application.Workbooks.Open("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\rshzbb.xlsx",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value
);
excelapp1.Application.ActiveWorkbook.SaveAs("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\rshzbb.aspx", Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml, Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
excelapp1.Application.Workbooks.Close();
excelapp1.Application.Quit();
excelapp1.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp1);
DateTime endTime = DateTime.Now;
killProcess(startTime, endTime, "EXCEL");
GC.Collect(); //回收垃圾
}
public void ReportxcfxToHtm()
{
DateTime startTime = DateTime.Now;
Microsoft.Office.Interop.Excel.Application excelapp2 = new Microsoft.Office.Interop.Excel.ApplicationClass();
excelapp2.Application.DisplayAlerts = false;
excelapp2.Application.Workbooks.Open("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\xcfxbb.xlsx",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value
);
excelapp2.Application.ActiveWorkbook.SaveAs("D:\\Program Files\\Kingdee\\K3ERP\\KDHR\\SITEFILE\\WEBUI\\js\\xcfxbb.aspx", Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml, Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value);
excelapp2.Application.Workbooks.Close();
excelapp2.Application.Quit();
excelapp2.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp2);
DateTime endTime = DateTime.Now;
killProcess(startTime, endTime, "EXCEL");
GC.Collect(); //回收垃圾
}
protected void killProcess(DateTime start, DateTime end, string ProcessName)
{
Process[] myProcesses;
DateTime ProStartTime;
myProcesses = Process.GetProcessesByName(ProcessName);
foreach (Process myProcess in myProcesses)
{
ProStartTime = myProcess.StartTime;
if (start <= ProStartTime && ProStartTime <= end)
{
myProcess.Kill();
}
}
}
}
}
- .net C# COM组件,实现EXCEL自动转换格式与如何退出EXCEL Process
- 如何转换EXCEL格式
- pdf格式转换成excel如何实现
- C# COM组件操作Excel
- C#实现使用Excel COM组件向Excel文件中添加图片的Demo
- C#使用Excel的COM组件操作Excel
- C#程序如何实现COM组件的自动注册
- asp.net两种方式在模板excel中插入图片:npoi和c# com组件
- 如何转换pdf格式为excel
- 如何将word转换成excel格式
- 如何把pdf转换excel表格格式
- 用ADO.NET实现txt与Excel的互相转换
- C#操作Excel时找不到“EXCEL9.OLB”com组件,可以通过如下方法实现:
- C# 操作 Excel 如何设置格式
- [转] C# 操作 Excel 如何设置格式
- C# 操作 Excel 如何设置格式
- C# 操作 Excel 如何设置格式
- 实现dataset与excel转换
- 当IDENTITY_INSERT设置为 OFF 时不能向表 '*' 中的标识列插入显式值
- sap的ides和ecc分别是什么意思
- 浏览器缓存和HTTP协议
- 黑马程序员--练习
- 2.1.2语音信号的可压缩性
- .net C# COM组件,实现EXCEL自动转换格式与如何退出EXCEL Process
- 猜数字[中国剩余定理]
- 关闭子窗口刷新父容代码:
- 如何为php cli模式独立创建配置文件
- 最小生成树(Kruskal)
- ORACLE_远程数据库同步
- accept 函数
- 黑马程序员--C#回顾
- 文件描述符、文件句柄、文件路径的转换接口