------解决方案-------------------- if (File.Exists(@"D:\\xxxx.xls")) { try { // 打开进行操作 } catch (Exception ex) { MessageBox.Show("错误\r\n" + ex.Message, "提示", MessageBoxButton.OK, MessageBoxImage.Error); return; } Excel的打开和追加内容,你百度下就有了
------解决方案-------------------- 给你操作Excel的代码,微软的 /****************************** Module Header ******************************\ * Module Name: Program.cs * Project: CSAutomateExcel * Copyright (c) Microsoft Corporation. * * The CSAutomateExcel example demonstrates how to use C# codes to create an * Microsoft Excel instance, create a workbook, and fill data into the * specified range, as well as how to clean up unmanaged COM resources and * quit the Excel application properly. * * This source is subject to the Microsoft Public License. * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL. * All other rights reserved. * * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. \***************************************************************************/
#region Using directives using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Reflection;
using Excel = Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices; #endregion