/// <summary> /// Генерация набора строк данных /// </summary> /// <param name="model">Модель</param> /// <returns></returns> public void GenerateSheetDataAddRowsList(ref ModelXmlExcel model) { foreach (var row in model.Row) { model.SheetData.Append(row); } }
/// <summary> /// Генерация ячеек и строк /// </summary> /// <returns></returns> public void GenerateCell(List <ModelRowFormat> listCellModel, ref ModelXmlExcel model) { foreach (var modelRowFormat in listCellModel) { List <string> listArray = new List <string>(); foreach (var modelCellFormat in modelRowFormat.ModelCell) { var enumColumn = GetExcelStrings().Skip(modelCellFormat.IndexCellStart - 1).Take(modelCellFormat.IndexCellFinish).ToArray(); foreach (var column in enumColumn) { Cell cell = new Cell() { CellReference = $"{column}{IndexRow}", DataType = CellValues.String }; listArray.Add($"{column}{IndexRow}"); var indexRow = enumColumn.ToList().IndexOf(column) + 1; cell.StyleIndex = modelCellFormat.StyleIndex; if (indexRow == 1) { cell.DataType = modelCellFormat.CellFormat; if (modelCellFormat.WidthColumn != null) { Column columnCell = new Column() { Min = (UInt32)modelCellFormat.IndexCellStart, Max = (UInt32)modelCellFormat.IndexCellStart, Width = modelCellFormat.WidthColumn, CustomWidth = true }; model.Сolumns.Append(columnCell); } CellValue cellValue = new CellValue(); cellValue.Text = modelCellFormat.ValueCell; cell.Append(cellValue); } model.Cell.Add(cell); } } Row row = new Row() { RowIndex = IndexRow, DyDescent = 0.25D, Height = modelRowFormat.HeightRow, CustomHeight = true, }; foreach (var cell in model.Cell) { row.Append(cell); } model.Cell.Clear(); model.Row.Add(row); IndexRow++; RowNameColumnsMatrix.Add(listArray); } }
/// <summary> /// Объединение ячеек /// </summary> /// <param name="listRowModel">Модель строк и ячеек</param> /// <param name="model">Модель xml</param> public void MergeCells(List <ModelRowFormat> listRowModel, ref ModelXmlExcel model) { var i = 0; foreach (var modelRowFormat in listRowModel) { foreach (var modelCellFormat in modelRowFormat.ModelCell) { if (modelCellFormat.MergeHorizontalInt != 0) { var list = RowNameColumnsMatrix[i].Skip(modelCellFormat.IndexCellStart - 1).Take(modelCellFormat.MergeHorizontalInt).ToList(); var first = list.First(); var last = list.Last(); MergeCell mergeCell = new MergeCell() { Reference = $"{first}:{last}" }; model.MergeCells.Append(mergeCell); } if (modelCellFormat.MergeVerticalInt != 0 && modelCellFormat.MergeHorizontalSquare == 0) { var listStart = RowNameColumnsMatrix[i].Skip(modelCellFormat.IndexCellStart - 1).ToList().First(); var listFinish = RowNameColumnsMatrix[i + modelCellFormat.MergeVerticalInt].Skip(modelCellFormat.IndexCellStart - 1).ToList().First(); MergeCell mergeCell = new MergeCell() { Reference = $"{listStart}:{listFinish}" }; model.MergeCells.Append(mergeCell); } if (modelCellFormat.MergeHorizontalSquare != 0 && modelCellFormat.MergeVerticalInt != 0) { var listStart = RowNameColumnsMatrix[i].Skip(modelCellFormat.IndexCellStart - 1).ToList().First(); var listFinish = RowNameColumnsMatrix[i + modelCellFormat.MergeVerticalInt].Skip(modelCellFormat.IndexCellStart - 1).Take(modelCellFormat.MergeHorizontalSquare).ToList().Last(); MergeCell mergeCell = new MergeCell() { Reference = $"{listStart}:{listFinish}" }; model.MergeCells.Append(mergeCell); } } i++; } }