Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
            }

        }



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.


Template file conditional formatting[^]


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.

Created excel file[^]

What I have tried:

I tried and I cant find anything related to this, seems we can write new conditional formatting.
Posted
Comments
Member 13076538 6-Nov-18 1:30am    
https://github.com/tonyqus/npoi
Member 13076538 6-Nov-18 1:30am    
Pls check this link
King Fisher 17-Jan-19 5:57am    
Thanks, Its resolved long back

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900