【发布时间】:2021-09-13 09:42:03
【问题描述】:
我使用此代码将 gridview 导出到 .Net Framework 4.7.2 上的 excel 没有任何问题
using (XtraSaveFileDialog saveDialog = new XtraSaveFileDialog())
{
saveDialog.Filter = "Excel (2007-2019) (.xlsx)|*.xlsx";
saveDialog.FileName = Resources.dailyProductionPaint;
if (saveDialog.ShowDialog() != DialogResult.Cancel)
{
XlsxExportOptionsEx options = new XlsxExportOptionsEx();
options.LayoutMode = DevExpress.Export.LayoutMode.Table;
string exportFilePath = saveDialog.FileName;
options.BeforeExportTable += ea =>
{
ea.Table.Style.Name = XlBuiltInTableStyleId.None;
};
gridControl2.ExportToXlsx(exportFilePath, options);
if (File.Exists(exportFilePath))
{
try
{
//Try to open the file and let windows decide how to open it.
System.Diagnostics.Process.Start(exportFilePath);
}
catch
{
String msg = Resources.openFileEr + Environment.NewLine + Environment.NewLine + Resources.path + exportFilePath;
XtraMessageBox.Show(msg, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
String msg = Resources.saveFileEr + Environment.NewLine + Environment.NewLine + Resources.path + exportFilePath;
XtraMessageBox.Show(msg, Resources.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
但是当我在 .net6 上运行相同的代码时,我得到了这个错误
System.ComponentModel.Win32Exception:“尝试使用工作目录“C:\Users\TestUser\Desktop”启动进程“C:\Users\TestUser\Desktop\Daily Result-Painting7.xlsx”时发生错误。指定的可执行文件不是此 OS 平台的有效应用程序。'
堆栈跟踪
“在 System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)\r\n 在 System.Diagnostics.Process.Start()\r\n 在 System.Diagnostics.Process.Start(ProcessStartInfo startInfo)\r\n在 System.Diagnostics.Process.Start(String fileName)\r\n 在 SmartWinForm.PL.FrmAssemblyDailyProduction.btnExportExcel_ItemClick(Object sender, ItemClickEventArgs e) 在 C:\Users\TestUser\source\repos\SmartWinForm\SmartWinForm\PL\FrmAssemblyDailyProduction .cs:line 198\r\n 在 DevExpress.XtraBars.BarItem.OnClick(BarItemLink 链接)\r\n 在 DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink 链接)\r\n 在 DevExpress.XtraBars.BarButtonItem.OnClick( BarItemLink 链接)\r\n 在 DevExpress.XtraBars.BarItemLink.OnLinkClick()\r\n 在 DevExpress.XtraBars.BarButtonItemLink.OnLinkClick()\r\n 在 DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs) \r\n 在 DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink 链接)\r\n 在 DevExpress.X traBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink 链接)\r\n 在 DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)\r\n 在 DevExpress.XtraBars.Controls.CustomPopupBarControl.OnMouseUp(MouseEventArgs e)\r\n n 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 DevExpress.XtraBars.Controls。 CustomControl.WndProc(Message& msg)\r\n at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam , IntPtr lparam)"字符串
【问题讨论】:
标签: c# winforms export-to-excel .net-6.0