/// <summary>生成Excel模板文件</summary> public void BuildExcelTemplateFile() { LoadFromApiService(false, true); var excelFile = this.Config.Product.ExcelFile; var excelSheet = ExcelUtil.CreateSheet(excelFile, "成果数据"); var rowIndex = 0; //加入第一行标题 var cellData = BuildExcelTemplateFirstTitleRow(); excelSheet.AddRow(rowIndex++, cellData, true); //加入第二行标题 cellData = BuildExcelTemplateSecondTitleRow(); excelSheet.AddRow(rowIndex++, cellData, false); //生成合并单元格 //excelSheet.BuildMergedRegion(0, 2, 0, 0); //excelSheet.BuildMergedRegion(0, 2, 1, 1); excelSheet.SetTitleStyle(0, 1); //加入成果文件 foreach (var tag in this.Config.MetadataTags) { tag.CheckDefaultValue(this.Config.Variables); } var ptFiles = Directory.GetFiles(this.Config.Product.Folder, "*.*", SearchOption.AllDirectories); for (int i = 0; i < ptFiles.Length; i++) { var ext = ptFiles[i].GetExtension(); cellData = BuildExcelTemplateDataRow(i, ptFiles[i], ext); excelSheet.AddRow(rowIndex++, cellData, false); } excelSheet.SetNumberStyle(2, 0); excelSheet.CreateFreezePane(3, 2); //设置列下拉列表 var startRow = 2; var encodingCol = 1; var startCol = 4; BuildExcelTemplateDropdownList(excelSheet, startRow, encodingCol, startCol); //保存 var excelWorkBook = excelSheet.Workbook; using (var stream = new FileStream(excelFile, FileMode.Create, FileAccess.Write)) { excelWorkBook.Write(stream); } excelWorkBook.Close(); }