This project has moved. For the latest updates, please go here.

Loading and Modifying Files

Loading a workbook created with ClosedXML:
            var workbook = new XLWorkbook("BasicTable.xlsx");

BasicTable.jpg

Modifying the workbook:
            var ws = workbook.Worksheet(1);

            // Change the background color of the headers
            var rngHeaders = ws.Range("B3:F3");
            rngHeaders.Style.Fill.BackgroundColor = XLColor.LightSalmon;

            // Change the date formats
            var rngDates = ws.Range("E4:E6");
            rngDates.Style.DateFormat.Format = "MM/dd/yyyy";

            // Change the income values to text
            var rngNumbers = ws.Range("F4:F6");
            foreach (var cell in rngNumbers.Cells())
            {
                cell.DataType = XLCellValues.Text;
                cell.Value += " Dollars";
            }

BasicTableModified.jpg

Saving the workbook:
            workbook.SaveAs("BasicTable_Modified.xlsx");

Last edited Jan 23, 2011 at 11:26 PM by MDeLeon, version 8