我试图用C#访问excel模块,保存excel文件后遇到麻烦。
有重复的本工作簿和工作表,如下图所示。
这仅在excel文件包含模块时发生,而如果excel在项目中仅包含工作表,则一切都会好起来。
这里的代码只不过是打开和保存同一文件而已。
我正在使用WIN10 / VS2013 / EXCEL 2010。
有人知道为什么会这样吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Vbe.Interop;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string filepath = @"C:\test.xls";
Excel._Application app = new Excel.Application();
Excel._Workbook workbook = app.Workbooks.Open(filepath);
workbook.SaveAs(filepath);
workbook.Close(true);
app.Quit();
}
}
}