Convert/Save HSSFWorkbook as XSSFWorkbook

Mar 21, 2013 at 12:10 PM
I'd like to know, if there is a way to save a HSSFWorkbook as XSSFWorkbook (and vice versa)
I tried the following, but it's not working:

HSSFWorkbook lXlsWorkbook = new HSSFWorkbook("c:\file.xls");
MemoryStream lMs = new MemoryStream();
lXlsWorkbook.write(lMs);
lMs.Position = 0;
XSSFWorkbook lXlsxWorkbook = new XSSFWorkbook(lMs); // Here the error occurs "wrong header"
FileStream lFs = new FileStream("c:\file.xlsx", FileMode.OpenOrCreate, FileAccess.Write);
lXlsxWorkbook.write(lFs);
lFs.Close();
lMs.Close();

Has someone done this before? Kind regards, Thomas
Mar 21, 2013 at 12:45 PM
Hi. I'm also very interested in this question. Please, someone! Help!!! :-)
May 11, 2013 at 2:01 PM
public void SaveExcel()
    {
        try
        {
            FileStream fwriter = new FileStream("c:\\ss.xlsx",FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            MemoryStream file = new MemoryStream();
            workbook.Write(file);
            file.WriteTo(fwriter);

        }
        catch (Exception)
        {
            throw;
        }
    }
void InitializeWorkbook()
    {

        workbook = new HSSFWorkbook();

        ////create a entry of DocumentSummaryInformation
        DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
        dsi.Company = "NPOI Team";
        workbook.DocumentSummaryInformation = dsi;

        ////create a entry of SummaryInformation
        SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
        si.Subject = "NPOI SDK Example";
        workbook.SummaryInformation = si;
        worksheet = workbook.CreateSheet("Sheet1");
    }

    public void AddData(int row, int col, string data)//, string format)
    {
        try
        {
            worksheet.CreateRow(row).CreateCell(col).SetCellValue(data);
        }
        catch (Exception)
        {
            throw;
        }
    }

Coordinator
Nov 17, 2013 at 11:28 PM
This is not easy because you need to copy every objects from HSSFWorkbook to XSSFWorkbook. For now, it's not supported by NPOI.