1.C#写的操作EXCEL应用 提示“office检测到此文件存在一个问题。为帮助保护您的计算机,不能打开此文件。 之前还正常,换个电脑就报错。
先手工打开Excel,会提示“受保护的视图”,不能编辑。点启用编辑就行了。再打开软件,正常了。
2.找不到引用microsoft.office.core
在项目引用中右击选择添加引用,选择COM里面选择Microft Office 12.0 object Library和Microft Excel 12.0 object Library分别点确定即可!同样如果要引用World选Microft World 12.0 object Library! 2003/2007共通处理方式 分别为11或12版本 添加.net中Microsoft.Office.Interop.excel; 添加.net中Office
3.源码示例
using System;
using System.Reflection;
using System.IO;
using Microsoft.Office.Interop.Excel;
namespace Excel
{
class Excel
{
public static int startRow =5;
public static string jzmc = "";
public static string id = "";
public static Double count = 0;
public static Array zw;
public static bool WriteXls(string filename, System.Collections.ArrayList rowData, int sheetNum)
{
//启动Excel应用程序
Microsoft.Office.Interop.Excel.Application xls = new Microsoft.Office.Interop.Excel.Application();
// _Workbook book = xls.Workbooks.Add(Missing.Value); //创建一张表,一张表可以包含多个sheet
//如果表已经存在,可以用下面的命令打开
_Workbook book = xls.Workbooks.Open(filename, Missing.Value, Missing.Value, Missing.Val