0

I am writing a very simple program. It runs without any errors. But nothing is written into the Excel file. Am I wrong somewhere?

  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);
}

1 Answer 1

1

Try

xlWorkSheet.Cells[1, 1].value = "input";     
Sign up to request clarification or add additional context in comments.

4 Comments

xlApp.Visible = True will show the sheet. Comment out the code that closes the workbook. Visually check if data has been written
Still nothing Tarik . I used to write like this and they all work fine until today . Something must be wrong somewhere...
It works on another PC just fine. Very nice guess Tarik. I still have no idea whats going on with my PC. thanks for your help though !
Try your code in a vbscript to determine if it is a .net specific issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.