gpt4 book ai didi

c# - 获取 'excelcnv.exe' 位置

转载 作者:太空宇宙 更新时间:2023-11-03 14:50:30 25 4
gpt4 key购买 nike

我正在使用 'excelcnv.exe''.xls' 文件转换为 '.xlsx' 版本。我可以通过直接在我现在工作的机器中引用“excelcnv.exe”位置来做到这一点。

在我当前的机器上,安装了 Office 2016,我直接引用了“excelcnv.exe”所在的位置。目前,对于 Office 2016 版本,它位于 'C:\Program Files (x86)\Microsoft Office\root\Office16' 位置。这取决于 office 版本和 office 安装位置

mstrExtAddedFilePath = pstrFilePath.Replace(".xls", ".xlsx");

string processFilePath = @"C:\Program Files (x86)\Microsoft Office\root\Office16\excelcnv.exe";
string processArguments = "-oice \"" + pstrFilePath + "\" \"" + mstrExtAddedFilePath + "\"";
Process process = new Process();
process.StartInfo.FileName = processFilePath;
process.StartInfo.Arguments = processArguments;
process.Start();

但是,我想在部署我的 DLL 的机器中动态获取“excelcnv.exe”的位置。部署环境可能安装32位或64位office甚至不同版本的office(2010/2013/2016)

如何获得? 注册表 中是否有可用的关键设置?

或者 excelcnv.exe 的任何其他替代方法 将文件转换为“.xlsx”格式?

最佳答案

我会简单地使用 GetFiles() 在所有目录中搜索此文件,例如像

var files = Directory.GetFiles(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"excelcnv.exe",
SearchOption.AllDirectories);

如果只有一个匹配项,您可以非常确定它是正确的,否则您可以检查某些模式的完整路径,例如完整路径中必须有 Office

编辑:围绕这个包装一些逻辑。保存用户设置的路径并在每次运行时从那里加载它。如果 exe 文件不存在 (File.Exist()) 开始新的搜索。

关于c# - 获取 'excelcnv.exe' 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51999697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com