Click here to Skip to main content
16,012,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai to all,
I want to create an Empty Excel file...
I Created Like this...

FileStream fs = new File.Create("MyFile.xlsx");
fs.Close();

I want to create an Empty Excel file... the above code is not working.
Getting Error when try to open that created Excel file.
Error: Excel cannot open the file MyFile.xlsx because the file format or file extension is not valid. Verify that...

Am using VS2010, MSOffic 2010.

How can i create an Empty Excel File...
Please help me
Posted
Comments
WrelleDube 17-Dec-15 5:15am    
satyagrahi here is another C# library for excel files that can enable you to do this, see here.
Also not only that you can even read an existing excel files in C# with it.

As per Manfred stated, you created an empty (Text) file.

If you are developing an ASP.NET application and/or an application that might not have MS Excel installed, then I suggest using Open XML SDK 2.0 from Microsoft. You will need to download and install the SDK prior to writing code that functions.

Download Open XML SDK 2.0 from here:

http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&displaylang=en


Here is a good reference on creating an Excel Workbook with Open XML:

http://blog.stuartwhiteford.com/?p=49

Hope this has helped,

Tom
 
Share this answer
 
Comments
Manfred Rudolf Bihy 29-Dec-10 15:16pm    
Good call!
satyagrahi_2010 8-Jan-11 0:36am    
Thanks for Replay
You just created an empty file which MS Excel cannot recognize. The file may have the right extension but it's not of MS Excel format.
Please go to the following site as they provide information on how to automate Excel tasks with C#.

You can use Excel C# interop to create the file but that also means that the computer running your application needs to have MS Excel installed.

http://support.microsoft.com/kb/302084[^]

Here is a link exploring an option when Excel is not installed on the computer running the application:

http://p2p.wrox.com/c/1745-create-excel-file-without-excel-being-installed.html[^]

Regards,

Manfred
 
Share this answer
 
v3
Comments
thatraja 29-Dec-10 11:19am    
Good answer Manfred
satyagrahi_2010 8-Jan-11 0:36am    
Thanks for replay

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900