Last active
November 30, 2017 08:33
-
-
Save Raggles/135763ca7994531de2f559282d3c94c4 to your computer and use it in GitHub Desktop.
NZISM Spreadsheet Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Text.RegularExpressions; | |
using OfficeOpenXml; | |
using System.Drawing; | |
namespace NZISMSpreadsheetGenerator | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var file = File.ReadAllText(args[0]); | |
Regex r = new Regex(@"\d+\.\d+\.\d+\.C\.\d\d\.(.|\n)*?\.\s*?\n"); | |
string s = ""; | |
ExcelPackage pck = new ExcelPackage(new FileInfo(args[1])); | |
var ss = pck.Workbook.Worksheets.Add("Checklist"); | |
ss.Cells[1, 1].Value = "MPNZ Compilance"; | |
ss.Cells[1, 2].Value = "Control #"; | |
ss.Cells[1, 3].Value = "Control Detail"; | |
ss.Cells["A1:C1"].AutoFilter = true; | |
ss.Cells["C:C"].Style.WrapText = true; | |
int i = 2; | |
foreach (Match m in r.Matches(file)) | |
{ | |
Regex r2 = new Regex(@"\d+\.\d+\.\d+\.C\.\d\d"); | |
var m2 = r2.Match(m.Value); | |
ss.Cells[i,2].Value = m2.Value; | |
ss.Cells[i,3].Value = m.Value; | |
i++; | |
} | |
var options = ss.DataValidations.AddListValidation("A2:A" + ss.Dimension.End.Row.ToString()); | |
options.Formula.Values.Add("Compliant"); | |
options.Formula.Values.Add("Partially Compliant"); | |
options.Formula.Values.Add("Non Compliant"); | |
options.Formula.Values.Add("Deliberately Non Compliant"); | |
options.Formula.Values.Add("Not Applicable"); | |
options.Formula.Values.Add("Under Consideration"); | |
options.Formula.Values.Add("Not Yet Assessed"); | |
var _cond1 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:"+ss.Dimension.End.Address)); | |
_cond1.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond1.Style.Fill.BackgroundColor.Color = Color.LightGreen; | |
_cond1.Formula = "=$A2=\"Compliant\""; | |
var _cond2 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:" + ss.Dimension.End.Address)); | |
_cond2.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond2.Style.Fill.BackgroundColor.Color = Color.LightSalmon; | |
_cond2.Formula = "=$A2=\"Non Compliant\""; | |
var _cond3 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:" + ss.Dimension.End.Address)); | |
_cond3.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond3.Style.Fill.BackgroundColor.Color = Color.LightYellow; | |
_cond3.Formula = "=$A2=\"Deliberately Non Compliant\""; | |
var _cond4 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:" + ss.Dimension.End.Address)); | |
_cond4.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond4.Style.Fill.BackgroundColor.Color = Color.LightYellow; | |
_cond4.Formula = "=$A2=\"Under Consideration\""; | |
var _cond5 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:" + ss.Dimension.End.Address)); | |
_cond5.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond5.Style.Fill.BackgroundColor.Color = Color.LightGray; | |
_cond5.Formula = "=$A2=\"Not Applicable\""; | |
var _cond6 = ss.ConditionalFormatting.AddExpression(new ExcelAddress("A2:" + ss.Dimension.End.Address)); | |
_cond6.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; | |
_cond6.Style.Fill.BackgroundColor.Color = Color.LightSkyBlue; | |
_cond6.Formula = "=$A2=\"Partially Compliant\""; | |
ss.Cells[1, 4].Value = "Compliant"; | |
ss.Cells[2, 4].Formula = string.Format("=COUNTIF(A2:A{0},\"Compliant\")", ss.Dimension.End.Row); | |
ss.Cells[1, 5].Value = "Partially Compliant"; | |
ss.Cells[2, 5].Formula = string.Format("=COUNTIF(A2:A{0},\"Partially Compliant\")", ss.Dimension.End.Row); | |
ss.Cells[1, 6].Value = "Non Compliant"; | |
ss.Cells[2, 6].Formula = string.Format("=COUNTIF(A2:A{0},\"Non Compliant\")", ss.Dimension.End.Row); | |
ss.Cells[1, 7].Value = "Non Compliant (deliberate)"; | |
ss.Cells[2, 7].Formula = string.Format("=COUNTIF(A2:A{0},\"Deliberately Non Compliant\")", ss.Dimension.End.Row); | |
ss.Cells[1, 8].Value = "Not applicable"; | |
ss.Cells[2, 8].Formula = string.Format("=COUNTIF(A2:A{0},\"Not Applicable\")", ss.Dimension.End.Row); | |
ss.Cells[1, 9].Value = "Under Consideration"; | |
ss.Cells[2, 9].Formula = string.Format("=COUNTIF(A2:A{0},\"Under Consideration\")", ss.Dimension.End.Row); | |
ss.Cells[1, 10].Value = "Not assessed"; | |
ss.Cells[2, 10].Formula = string.Format("={0}-Sum(D2:H2)", ss.Dimension.End.Row); | |
ss.Cells[ss.Dimension.Address].AutoFitColumns(); | |
ss.Column(3).Width = 90; | |
pck.Save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment