예제 #1
0
 public bool ExportStandardLinkageDataToExcel(ref IExcelService excelService, List <LinkageConfigStandard> models, string sheetName)
 {
     try
     {
         if (models.Count > 0)
         {
             #region 标准组态表头
             IControllerConfig     config = ControllerConfigManager.GetConfigObject(ControllerType.FT8000);
             ColumnConfigInfo[]    deviceColumnDefinitionArray = config.GetStandardLinkageConfigColumns(); //取得标准组态的列定义信息
             List <MergeCellRange> lstMergeCellRange           = new List <MergeCellRange>();
             int currentRowIndex = 0;
             excelService.SetCellValue(sheetName, currentRowIndex, 0, sheetName, CellStyleType.SubCaption);
             currentRowIndex++;
             for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++)
             {
                 excelService.SetCellValue(sheetName, currentRowIndex, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead);
             }
             MergeCellRange mergeCellRange = new MergeCellRange();
             mergeCellRange.FirstRowIndex    = 0;
             mergeCellRange.LastRowIndex     = 0;
             mergeCellRange.FirstColumnIndex = 0;
             mergeCellRange.LastColumnIndex  = deviceColumnDefinitionArray.Length - 1;
             lstMergeCellRange.Add(mergeCellRange);
             excelService.SetMergeCells(sheetName, lstMergeCellRange);
             foreach (var model in models)
             {
                 currentRowIndex++;
                 excelService.SetCellValue(sheetName, currentRowIndex, 0, model.Code, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 1, model.DeviceNo1, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 2, model.DeviceNo2, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 3, model.DeviceNo3, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 4, model.DeviceNo4, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 5, model.DeviceNo5, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 6, model.DeviceNo6, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 7, model.DeviceNo7, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 8, model.DeviceNo8, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 9, model.ActionCoefficient.ToString(), CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 10, model.LinkageNo1, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 11, model.LinkageNo2, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 12, model.LinkageNo3, CellStyleType.Data);
                 excelService.SetCellValue(sheetName, currentRowIndex, 13, model.Memo, CellStyleType.Data);
             }
             excelService.SetColumnWidth(sheetName, 13, 50f);
             #endregion
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
예제 #2
0
        protected override bool GenerateExcelTemplateStandardSheet(List <string> sheetNames, int currentIndex, int loopSheetAmount, int maxLinkageAmount, ref IExcelService excelService)
        {
            try
            {
                #region 标准组态表头
                List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>();

                IControllerConfig  config = ControllerConfigManager.GetConfigObject(ControllerType.FT8003);
                ColumnConfigInfo[] deviceColumnDefinitionArray = config.GetStandardLinkageConfigColumns(); //取得标准组态的列定义信息

                excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], 0, 0, sheetNames[loopSheetAmount + currentIndex], CellStyleType.SubCaption);
                for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++)
                {
                    excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], 1, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead);
                }
                MergeCellRange mergeCellRange = new MergeCellRange();
                mergeCellRange.FirstRowIndex    = 0;
                mergeCellRange.LastRowIndex     = 0;
                mergeCellRange.FirstColumnIndex = 0;
                mergeCellRange.LastColumnIndex  = deviceColumnDefinitionArray.Length - 1;
                lstMergeCellRange.Add(mergeCellRange);
                excelService.SetMergeCells(sheetNames[loopSheetAmount + currentIndex], lstMergeCellRange);//设置"标准组态页签"合并单元格
                for (int i = 2; i < maxLinkageAmount + 3; i++)
                {
                    for (int j = 0; j < deviceColumnDefinitionArray.Length; j++)
                    {
                        excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], i, j, null, CellStyleType.Data);
                    }
                }
                mergeCellRange = new MergeCellRange();
                mergeCellRange.FirstRowIndex    = 2;
                mergeCellRange.LastRowIndex     = maxLinkageAmount + 2;
                mergeCellRange.FirstColumnIndex = 5;
                mergeCellRange.LastColumnIndex  = 5;
                excelService.SetSheetValidationForListConstraint(sheetNames[loopSheetAmount + currentIndex], RefereceRegionName.ActionCoefficient.ToString(), mergeCellRange);

                #endregion
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }