另一个可能的选项 - 只需使用 C# 中的进程复制文件,创建一个进程将文件从 xls 复制到 xlsx。没有大惊小怪,没有混乱。这是在 .Net Core 6.0 和 o365 中。
最终,您在进程中运行的字符串(也称为命令提示符)应该类似于:
"C:\Program Files (x86)\Microsoft Office\root\Office16\excelcnv.exe"
-oice "\Share\Folder\Cash.xls" "\Share\Folder\Cash.xlsx"
public static class Xls2XlsxCmdProcess
{
public static string processDirectory = @"C:\Program Files (x86)\Microsoft Office\root\Office16\";
public static void ExecuteCommandSync(string pathToExe, string command)
{
var procStartInfo = new ProcessStartInfo(pathToExe, command)
{
WorkingDirectory = processDirectory,
CreateNoWindow = false,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
var proc = new Process { StartInfo = procStartInfo };
proc.Start();
//proc.StandardInput.WriteLine(password);//If the app that requires a password or other params, they can be added here as a string.
proc.StandardInput.Flush();
// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
Console.WriteLine(result);
Console.WriteLine(error);
}
}
要调用它,请指定所有参数、工作目录,然后就可以开始比赛了!!!
string baseFolder = @"\\Share\folder\";
string fileNameCash = "Cash.xls";
string fileNameCashOutput = "Cash.xlsx";
//Create cash as xlsx files (for ease of use with EPPlus4)
string pathToExe = @"C:\Program Files (x86)\Microsoft Office\root\Office16\excelcnv.exe";//Path to office XLS to XLSX Conversion Tool for o365 - You can find a similar version by searching for the excelcnv.exe within "C:\Program Files (x86)\Microsoft Office" folder.
string commandFormat1 = string.Format(@"""{0}"" -oice ""{1}{2}"" ""{3}{4}"" ",pathToExe, @BaseFolder, fileNameCash,@BaseFolder,fileNameCashOutput);
Xls2XlsxCmdProcess.ExecuteCommandSync(pathToExe, string.Format(commandFormat1));