Hi.
I'm creating a Excel export function for SQL server. I have the following bit of code in my Visual C# CLR Database Project...
Best regards
/Henning
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();
else
workbook = new HSSFWorkbook();
// Some other stuff
Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
FileStream file = new FileStream(outputFile, FileMode.Create);
workbook.Write(file);
file.Close();
}
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
/Henning