C# 自动刷新excel表格
我制作了一个小型控制台应用程序,用于刷新程序所在目录中的所有excel文件。 它在pc上运行得非常好,但当我在普通客户端windows pc上使用它时,它甚至无法启动 为了使它工作,是否需要安装任何东西 代码:C# 自动刷新excel表格,c#,excel,resources,auto-update,C#,Excel,Resources,Auto Update,我制作了一个小型控制台应用程序,用于刷新程序所在目录中的所有excel文件。 它在pc上运行得非常好,但当我在普通客户端windows pc上使用它时,它甚至无法启动 为了使它工作,是否需要安装任何东西 代码: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using Microsoft.Office.Interop.Excel; usi
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace CNTExcelUpdate_Invisible
{
class Program
{
static string path = System.Reflection.Assembly.GetEntryAssembly().Location;
static void Main(string[] args)
{
path = Path.GetDirectoryName(path);
updateDirectory(path);
Environment.Exit(0);
}
public static void updateDirectory(string path)
{
int amount = 0;
string[] files;
files = Directory.GetFiles(path, "*.xlsx", SearchOption.AllDirectories);
amount += files.Count();
int counter = 0;
try
{
foreach (var file in Directory.EnumerateFiles(path, "*.xlsx", SearchOption.AllDirectories))
{
string fileName = Path.GetFileName(file);
if (fileName.Substring(0, 2).Equals("GK"))
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(file,
0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
excelApp.DisplayAlerts = false;
excelWorkbook.RefreshAll();
System.Threading.Thread.Sleep(1000);
excelApp.Quit();
excelApp = null;
excelWorkbook.SaveAs(file, Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
//excelWorkbook.Close();
Marshal.ReleaseComObject(excelWorkbook);
excelWorkbook = null;
}
counter++;
Console.Write(counter.ToString() + "/" + amount.ToString() + " Dateien verarbeitet");
Console.SetCursorPosition(0,0);
}
}
catch (Exception e)
{
MessageBox.Show("Fehler bei der Verbindung: \r\n" + e.ToString());
}
}
}
}
“不起作用”到底是什么意思?会发生什么?错误是什么?这就是重点。它根本不起作用。没有错误。没有什么能告诉我发生了什么。我包括了MessageBox来显示异常,但是没有异常。通常情况下,控制台应打开。您将看到一个整数(工作表总数)和另一个整数,该整数在处理工作表时进行计数。但没有什么。控制台无法打开。