早上好
我对此进行了无休止的研究,并尝试了几种解决方案,但均未成功。这种异常可能发生四分之一的尝试以节省测试。单击“保存”按钮后,将开始出现“保存对话框”,冻结一秒钟,然后关闭该应用程序。我尝试过[StaThread],但没有帮助。任何建议,将不胜感激。提前致谢。我的代码在下面。
private void button4_Click(object sender, EventArgs e)
{
try
{
using (SaveFileDialog SFD = new SaveFileDialog() { Filter = "Excel Workbook|*.xls", ValidateNames = true })
{
SFD.FileName = textBox11.Text.ToString();
if (SFD.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Workbook wb = app.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)app.ActiveSheet;
ws.Name = textBox11.Text.ToString();
app.Visible = false;
int i = 2;
foreach (ListViewItem item in lstLocal.Items)
wb.SaveAs(SFD.FileName, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
wb.Close();
app.Quit();
wb = null;
app = null;
MessageBox.Show("File has been saved!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
catch
{
MessageBox.Show("Something went wrong!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
答案 0 :(得分:0)
对于此问题的关闭,事实证明我开发的钻机异常。此后,由于其他原因,我不得不擦除它并重新安装Win10 / vS2017,该问题不再存在。新安装的已编译应用在开发平台或任何其他平台上不再具有此问题。奇怪〜谢谢你的帮助和建议。