标签:temp 全局 com int tag work let can 处理
一、准备:想要操作Excel,先要在添加2个COM引用:
1、Microsoft Excel 14.0 Object Library (版本不同14.0也可能是12.0等)
2、Microsoft Office 14.0 Object Library
二、操作:
在Winform中,也须添加引用
using Microsoft.Office.Interop.Excel;
public partial class FrmExcelOp : Form
{
private Microsoft.Office.Interop.Excel.Application excel; //定义一个变量供全局使用
object missing = System.Reflection.Missing.Value; //定义一个参数变量供全局使用
private void OPExcel()
{
#region Excel准备阶段
if (!Directory.Exists(tagTempFolder))
{
Directory.CreateDirectory(tagTempFolder);
}
if (!Directory.Exists(tagFolder))
{
Directory.CreateDirectory(tagFolder);
}
if (excel2 == null)
{
excel2 = new Microsoft.Office.Interop.Excel.Application
{
UserControl = true
};
}
if (excel2 == null)
{
CancelBgwork(bgwk);
MyMsg.Stop("无法打开EXCEL,请检查系统配置.");
return;
}
//直接删除已存在的文件
if (File.Exists(tagISPFullName))
{
File.Delete(tagISPFullName);
}
#endregion
}
}
未完待续...
标签:temp 全局 com int tag work let can 处理
原文地址:https://www.cnblogs.com/imes/p/9732752.html