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.
These formats and colors are not appearing on the created excel file, but I can able to see the rules when check in conditional formatting but formats not applied.