I've a excel file in *.xlsx format. I want convert this file into *.xls format in my MVC Web application. In my application hosted server there is no Microsoft.Office package. Please let me know how we can achieve it in NPOI with c#.
Thanks in advance.
This is my suggest :
Use this library to read excel files in format 2007 https://excelpackage.codeplex.com/
Use this library to save file as format 2003 https://code.google.com/p/excellibrary/
It is possible in general, but not quite easy.
XLS
file format is handled byHSSFWorkbook
class (and accordingHSSFSheet
and so on).XLSX
file format is handled byXSSFWorkbook
class (andXSSFSheet
and so on).So in order to convert your file from
XLSX
toXLS
you need to:XSSFWorkbook
, load data to it from file;HSSFWorkbook
;HSSFSheet
and copy all the data from original worksheet to this new oneHSSFWorkbook
to file.So there is a lot of work to be done here, and this is significantly complicated task.
Probably NPOI is not the best solution in your case.
I found the solution based on the Andy's suggestion. Here is the source code which is customized to convert XLSX to XLS.