Convert xlsx file to xls using NPOI in c#

后端 未结 3 1101
一个人的身影
一个人的身影 2021-01-14 22:59

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 packa

3条回答
  •  天命终不由人
    2021-01-14 23:29

    It is possible in general, but not quite easy.

    XLS file format is handled by HSSFWorkbook class (and according HSSFSheet and so on). XLSX file format is handled by XSSFWorkbook class (and XSSFSheet and so on).

    So in order to convert your file from XLSX to XLS you need to:

    • create XSSFWorkbook, load data to it from file;
    • create new HSSFWorkbook;
    • for each worksheet in original file create HSSFSheet and copy all the data from original worksheet to this new one
    • write your HSSFWorkbook 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.

提交回复
热议问题