private static void CreateExcel(string filename) { var workbook = new XSSFWorkbook(); try { var sourcebook = AppDomain.CurrentDomain.BaseDirectory + "" + "\\App_Data\\Copy of VHC_modified_Report.xlsx"; using (FileStream file = new FileStream(sourcebook, FileMode.Open, FileAccess.ReadWrite)) { workbook = new XSSFWorkbook(file); } XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook); // evaluator.EvaluateAll(); string filePath = AppDomain.CurrentDomain.BaseDirectory + "" + "App_Data\\" + filename; using (var fileData = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite)) { workbook.Write(fileData); workbook.Close(); } } catch (Exception ex) { throw new Exception("ExportToExcel: \n" + ex.Message); } }
Code: private static void CreateExcel(string filename) { var workbook = new XSSFWorkbook(); try { var sourcebook = AppDomain.CurrentDomain.BaseDirectory + "" + "\\App_Data\\Copy of VHC_modified_Report.xlsx"; using (FileStream file = new FileStream(sourcebook, FileMode.Open, FileAccess.ReadWrite)) { workbook = new XSSFWorkbook(file); } XSSFFormulaEvaluator evaluator = new XSSFFormulaEvaluator(workbook); // evaluator.EvaluateAll(); string filePath = AppDomain.CurrentDomain.BaseDirectory + "" + "App_Data\\" + filename; using (var fileData = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite)) { workbook.Write(fileData); workbook.Close(); } } catch (Exception ex) { throw new Exception("ExportToExcel: \n" + ex.Message); } } From the above I can able to create excel sheet from the template file. But the Template Excel file, I have some conditional formatting rules and based on the rules applying some formats and filling colors.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)