Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Can any one kindly please guide me the code for converting .XLS to .XLSX format in C#.


Thanks
Posted
Updated 3-Apr-11 20:56pm
v4

There is no publicly available code to convert a spreadsheet that I'm aware of. However, I believe you could use the Object Model to open the old spreadsheet and use Save As
 
Share this answer
 
Hello.

Just elaborating on solution #1.

All you need to do is start a process with a few command line arguments.

For example:

string processFilePath = Environment.GetEnvironmentVariable("ProgramFiles") + @"\Microsoft Office\Office12\excelcnv.exe";
string processArguments = "-oice \"" + fileName + "\" \"" + Path.GetDirectoryName(fileName) + @"\" + Path.GetFileNameWithoutExtension(fileName) + ".xlsx\"";
Process process = new Process();
process.StartInfo.FileName = processFilePath;
process.StartInfo.Arguments = processArguments;
process.Start();



Valery.
 
Share this answer
 
Comments
pjhelp 13-Apr-11 2:28am    
Thank you Valery.
Your guide lines helped me a lot to resolve my issue.
pjhelp 13-Apr-11 2:36am    
Valery,
Can we generate XLS file even though Microsoft EXCLE is not exist in client machine programatically. Whether the above code stuff can generate for us ?

Right now i don't have a machine which is not having MS EXCEL ,to test this.If you have any concrete idea then kindly please let me know soon. Thaks again.
VivekKashyap 13-Nov-11 0:42am    
Valery,

I tried executing the above code. It is working fine. But for some excels, am getting many pop-ups.
1. Asking me to choose safemode or cancel.
2. Microsoft picture manager installer.
3. Ask for restart after installation is completed (Ref.2).

I tried adding "/safe" as a parameter. But fails for some inputs.

string processArguments = "/safe -oice \"D:\\Ver_12.xls\" \"" + Path.GetDirectoryName("D:\\") + @"\" + Path.GetFileNameWithoutExtension("Ver_12") + ".xlsx\"";


Please can you help me out cracking this.
Hellflip 9-May-12 3:26am    
Hi,
I have the same problem.
I don't know how remove the pop-ups, have you found a solving?

Thanks
jackie.3981 11-Oct-17 14:36pm    
Awesome!! It works!!
Thank you Valery.
Your guide lines helped me a lot to resolve my issue.
This[^] could help you. You however need to use this programmatically.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Mar-11 16:27pm    
Good idea, my 5.
--SA
Abhinav S 1-Apr-11 0:05am    
Thanks.
Hope this[^] might help you.
 
Share this answer
 
Comments
hc_chin 21-Mar-14 6:05am    
Dear All,

Just wander where does the .xlsx file will be stored after the conversion ?

I am try to convert this a few time.. it seem not working, perhaps you guys could share it sample project file..

Thanks..

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