コード例 #1
0
        static void Main(string[] args)
        {
            var workbook = GetWorkbook(ExcelPath);

            var inputSheet = workbook.GetSheet("Input");

            if (inputSheet == null)
            {
                Console.WriteLine("Could not find input.");
                return;
            }

            // door infos
            var inputDoorCells = inputSheet.GetRow(11).GetCells(6);

            /*
             * Type of door / Calculation / Cycles / Cable Drum / Spring DInside / Number of springs
             * Type of door: Data!Z15
             * Calculation: Data!V8
             * Cycles: Data!N12
             * Cable Drum: Data!AH22
             * Sprint DInside: Data!N22
             * Number of springs: Calculation!B41
             */
            var dataSheet        = workbook.GetSheet("Data");
            var data             = dataSheet.GetCellsFromReference(new[] { "Z15", "V8", "N12", "AH22", "N22" }).ToList();
            var calculationSheet = workbook.GetSheet("Calculation");
            var springNumber     = calculationSheet.GetCellFromReference("B41");
            var results          = workbook.GetSheet("Input").GetRows(new[] { 17, 18 }).Select(x => x.GetCells(9));

            data.First().SetCellValue((int)Options.TypeOfDoorOperation.MechanicalIndustrial1And1_4Inches);
            // workbook.EvaluateAll();

            // Compare results to excel.
            var tempPath = $"{Directory}AlcomexTor-Modified_{Guid.NewGuid()}.xls";
            var fStream  = new FileStream(tempPath, FileMode.Create, FileAccess.Write);

            workbook.Write(fStream);
            fStream.Dispose();


            var modified         = new FileStream(tempPath, FileMode.Open, FileAccess.ReadWrite);
            var modifiedWorkbook = new HSSFWorkbook(modified);

            modifiedWorkbook.EvaluateAll();

            var test = modifiedWorkbook.GetSheet("Input").GetRows(new[] { 17, 18 }).Select(x => x.GetCells(9));

            Console.WriteLine();
            File.Delete(tempPath);
        }