excel 互操作保存不工作

excel interop saveas not working

我有以下用于在 c# 中创建和保存 excel 文件的代码,但是当它完成时,没有文件创建到我的桌面,我不知道我做错了什么:

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

xlApp.Visible = false;

Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = (Worksheet)wb.Worksheets[1];
Range rangeAToC = ws.get_Range("A1", "C1");

string[] headerRow = { "GIP Id", "First Name", "Last Name"};

int indexAtRow = 0;
foreach (Range cell in rangeAToC)
{
    cell.Value2 = headerRow[indexAtRow];
    indexAtRow++;
}

//Save report
wb.SaveAs("C:/Users/Abdul/Desktop/GipEmployeeReport.xls", Type.Missing,
 Type.Missing,Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,
 Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

//Close out COM objects
xlApp.Workbooks.Close();
xlApp.Quit();

我注意到的第一件事是您使用正斜杠 (/) 而不是反斜杠 \