0

私は非常に単純なプログラムを書いています。エラーなしで実行されます。しかし、Excel ファイルには何も書き込まれません。私はどこか間違っていますか?

  using Excel = Microsoft.Office.Interop.Excel;

  // I already add this reference into my project

  public Write()
  {
        Excel.Application xlApp;
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;

        xlApp = new Excel.Application();
        xlWorkBook = xlApp.Workbooks.Open(Directory.GetCurrentDirectory() + "\\KKK.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        // This is all I want to write to my Excel file

        xlWorkSheet.Cells[1, 1] = "input";

        xlWorkBook.SaveAs(Directory.GetCurrentDirectory() + "\\KQ" + ThoiGian(), Excel.XlFileFormat.xlWorkbookDefault, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
        xlWorkBook.Close(true, misValue, misValue);
        xlApp.Quit();

        releaseObject(xlApp);
        releaseObject(xlWorkBook);
        releaseObject(xlWorkSheet);
}
4

1 に答える 1

1

試す

xlWorkSheet.Cells[1, 1].value = "input";     
于 2013-10-04T05:11:38.450 に答える