locked
How to create Excel file in C# RRS feed

  • Question

  • I followed the example below:

    http://csharp.net-informations.com/excel/csharp-create-excel.htm

     

    On the first run-through, the code fired and supposedly saved the file.  The next time I ran it, I got a message saying the file exists, would I like to overwrite it.  I said ok.  Then I went to look for the file and couldn’t find it anywhere.  I ran the code again, and again, I got prompted about whether or not I wanted to overwrite the file.  I said yes.  I still can’t find the file.  It certainly is NOT in c:\

    I used Start > Search to find the file.  Even that utility can’t find the file.  I did it again: yes, overwrite.  Still, the file is NOT there.

    AFAIK, this saves the file:

    xlWorkBook.SaveAs("csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

     

    Supposedly, this confirms the location of the saved file:

    MessageBox.Show("Excel file created , you can find the file c:\\csharp-Excel.xls")

    If there are any hidden files in that folder, I will still see a ghost image.  There is simply nothing there, but C# seems to think there IS something there.  Any ideas on what’s going on?

     

    Thanks everyone!!

    Monday, February 21, 2011 6:10 PM

Answers

  • Hi Ryguy72,

    Base on your description, you cannot find the excel file after you run the application.

    "Everything" is an administrative tool that locates files and folders by filename instantly for Windows.
    Unlike Windows search "Everything" initially displays every file and folder on your computer (hence the name "Everything").
    You type in a search filter to limit what files and folders are displayed.

    I have run your code and use the tool to find the excel file is under C:\\Users\Cookie\Documents (display as My Documents in disk).

    Please try the tool to find the file.

    Good luck to you.

    "This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie Luo Thursday, March 3, 2011 9:24 AM
    Wednesday, February 23, 2011 9:19 AM

All replies

  • Same thing with this sample:

    http://csharp.net-informations.com/excel/csharp-format-excel.htm

    Code fires, and (supposedly) creates a file.  Second time through, C# asks me if I want to overwrite the file...even thouse no file appears to exist.  I can't find it and Windows 'Search' can't find it.  If that little dog scratching around can't find the file, why does C# find the file? 

    Thanks!!

     

    • Proposed as answer by Umisha ShahBanned Wednesday, February 23, 2011 9:59 AM
    • Unproposed as answer by Cookie Luo Thursday, March 3, 2011 9:24 AM
    Monday, February 21, 2011 7:11 PM
  • Hi Ryguy72,

    Base on your description, you cannot find the excel file after you run the application.

    "Everything" is an administrative tool that locates files and folders by filename instantly for Windows.
    Unlike Windows search "Everything" initially displays every file and folder on your computer (hence the name "Everything").
    You type in a search filter to limit what files and folders are displayed.

    I have run your code and use the tool to find the excel file is under C:\\Users\Cookie\Documents (display as My Documents in disk).

    Please try the tool to find the file.

    Good luck to you.

    "This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Cookie Luo[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cookie Luo Thursday, March 3, 2011 9:24 AM
    Wednesday, February 23, 2011 9:19 AM
  • Thursday, October 13, 2011 8:35 AM
  • Hi,

    try to C# create Excel file with this C# / VB.NET Excel component.

    Here is a sample C# code, there should not be any problems with "ghost files":

    ExcelFile ef = new ExcelFile();
     
    // Adds new worksheet to excelFile.
    ExcelWorksheet ws = ef.Worksheets.Add("New worksheet");
     
    // Sets the value of the cell "A1".
    ws.Cells["A1"].Value = "Hello world!";
     
    // Saves the excel file.
    ef.SaveXls("excelFile.xls");

    Thursday, May 3, 2012 10:33 AM