コード例 #1
0
        private void CreateFromTemplate(string templateFilePath)
        {
            Application excel = new Application();

            _workbook = excel.Workbooks.Open(templateFilePath);
            var worksheets = _workbook.Worksheets;

            foreach (var ws in worksheets)
            {
                Worksheet worksheet = (Worksheet)ws;
                if (worksheet.Name == "Facilities")
                {
                    _facilitiesWorksheet = new FacilitiesWorkSheet(worksheet);
                }
                else if (worksheet.Name == "Devices")
                {
                    _devicesWorksheet = new DevicesWorksheet(worksheet);
                }
                else if (worksheet.Name == "Facilities schedule")
                {
                    _facilitiesScheduleWorksheet = new FacilitiesScheduleWorksheet(worksheet);
                }

                Debug.WriteLine($"{worksheet.Name}");
            }
        }
コード例 #2
0
        private void CreateFromScratch()
        {
            _Application excel = new _Excel.Application();

            _workbook = excel.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

            // create worksheets
            var worksheet = _workbook.Worksheets[1];

            _facilitiesWorksheet = new FacilitiesWorkSheet(worksheet);
            _facilitiesWorksheet.Init();

            worksheet = excel.Worksheets.Add(After: worksheet);
            _facilitiesScheduleWorksheet = new FacilitiesScheduleWorksheet(worksheet);
            _facilitiesScheduleWorksheet.Init();

            worksheet         = excel.Worksheets.Add(After: worksheet);
            _devicesWorksheet = new DevicesWorksheet(worksheet);
            _devicesWorksheet.Init();
        }