public SpreadsheetInfoContainer(FileInfo configurationFile)
        {
            StreamReader reader  = new StreamReader(configurationFile.ToString());
            ushort       lineNum = 0;

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                if (line.StartsWith("#"))
                {
                    continue;
                }
                else
                {
                    line = line.Trim();
                    lineNum++;
                    if (lineNum == 1)
                    {
                        dataHeadingLine = ushort.Parse(line);
                    }
                    else if (lineNum == 2)
                    {
                        dataStartLine = ushort.Parse(line);
                    }
                    else if (lineNum > 2 && lineNum < 29)
                    {
                        string           letter = line.Split(',')[1].Trim();
                        ExcelCellAddress addr   = new ExcelCellAddress(letter + dataStartLine);
                        ushort           column = (ushort)addr.Column;
                        columnNumbers.Add((ColumnType)lineNum - 3, column);
                    }
                    else if (lineNum >= 29)
                    {
                        if (line.Trim() == "")
                        {
                            continue;
                        }
                        string accName       = line.Split(',')[0].Trim();
                        string accIdentifier = line.Split(',')[1].Trim();
                        accounts.Add(accName, accIdentifier);
                    }
                }
            }
            instance = this;
        }
Example #2
0
        public MTFileHandler(FileInfo fileInfo, string worksheetName)
        {
            //ExcelPackage ep = new ExcelPackage(new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "lol.xlsx"));
            //ep.Workbook.Worksheets.Add("lol");
            //ep.Workbook.Worksheets["lol"].Cells[1, 1].AddComment("Hello", "Me");
            //ep.Save();


            package = new ExcelPackage(fileInfo);
            ExcelWorkbook workbook = package.Workbook;

            if (workbook.Worksheets[worksheetName] == null)
            {
                TemplateHandler th = new TemplateHandler();
                moneySpreadsheet = th.CreateAWorksheetFromTemplate(workbook, worksheetName);
                //FileInfo templatesFile = new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar +
                //								  "Templates" + Path.DirectorySeparatorChar + "MTTemplate.xlsx");
                //ExcelPackage copyPackage = new ExcelPackage(templatesFile);

                //moneySpreadsheet = workbook.Worksheets.Add("2018xb", copyPackage.Workbook.Worksheets[1]);
                if (!Directory.Exists(package.File.Directory.FullName))
                {
                    Directory.CreateDirectory(package.File.Directory.FullName);
                }
                if (!File.Exists(package.File.FullName))
                {
                    package.SaveAs(package.File);
                }
            }
            else
            {
                moneySpreadsheet = workbook.Worksheets[worksheetName];
            }

            interactor    = new MTSpreadsheetInteractor(moneySpreadsheet, this);
            infoContainer = new SpreadsheetInfoContainer(new FileInfo(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "MTConfig.txt"));
        }