This project is read-only.

Error when creating instance of XSSFWorkbook in Visual C# CLR Database Project

Aug 13, 2014 at 4:59 PM
Edited Aug 13, 2014 at 5:06 PM

I'm creating a Excel export function for SQL server. I have the following bit of code in my Visual C# CLR Database Project...
public static void CreateExcelFile(SqlDataReader rdr, string outputFile, bool includeHeading)
    IWorkbook workbook;

    if (outputFile.ToLower().EndsWith(".xlsx"))
        workbook = new XSSFWorkbook();
        workbook = new HSSFWorkbook();

    // Some other stuff

    FileStream file = new FileStream(outputFile, FileMode.Create);
When I set the output file to something ending with .xls, it works like a charm, and I get the expected Excel result file. But when I specify the output file to something ending with .xlsx i get an exception at the "workbook = new XSSFWorkbook();" line. The exception message is empty and the stacktrace look like the following:
   at NPOI.POIXMLDocument.GetProperties()
   at NPOI.XSSF.UserModel.XSSFWorkbook.OnWorkbookCreate()
   at StoredProcedures.CreateExcelFile(SqlDataReader rdr, String outputFile, Boolean includeHeading)
   at StoredProcedures.ExportExcel(String sql, String outputFile, Boolean includeHeading)
I've tried to reproduce the problem in a console application without luck. Seems like there's something when running in the SQL Server. Anyone got any suggestions?

Best regards