Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Excel - How to format cell as Yes/No instead of TRUE/FALSE

Tags:

excel

I use Epplus to export excel as following

        FileInfo newFile = new FileInfo(@"sample6.xlsx");
        using (ExcelPackage pck = new ExcelPackage(newFile))
        {
            var ws = pck.Workbook.Worksheets.Add("Content");
            ws.Cells["A1"].Value = true;
            ws.Cells["A2"].Value = false;
            pck.Save();
        }

The result excel show TRUE and FALSE

image

How can I show those cells as Yes/No

like image 860
Minh Phan Avatar asked Aug 23 '17 09:08

Minh Phan


People also ask

How do you format cells based on yes or no?

Highlight the cell range, Click on Conditional Formatting > Highlight Cell Rules > Text that Contains to create the Rule, then type YES in the Text that Contains dialog box.

Can you format MS Excel cells if yes?

To format a cell in Microsoft Excel, start by highlighting the specific cell you want to format. Then, right-click on the cell and click on "Format Cells." Choose whatever formatting you want for the cell from the different options, then click "Okay." That's all there is to it!


1 Answers

You should use excel template with custom format "Yes";;"No";

YesNo

Then load that template and write 1/0 instead of True/False

        FileInfo newFile = new FileInfo(@"sample6.xlsx");
        using (ExcelPackage pck = new ExcelPackage(newFile))
        {
            var ws = pck.Workbook.Worksheets["Content"];
            ws.Cells["A1"].Value = 1;
            ws.Cells["A2"].Value = 0;
            pck.Save();
        }
like image 132
Jacob Phan Avatar answered Sep 29 '22 22:09

Jacob Phan