コード例 #1
0
        private static void ConfigureRow(this IXLWorksheet xlSheet, Row row, List <ColumnProps> columnProps, bool isSheetLocked)
        {
            foreach (var rowCell in row.Cells)
            {
                if (rowCell.Visible is false)
                {
                    continue;
                }

                xlSheet.ConfigureCell(rowCell, columnProps, isSheetLocked);
            }

            // Configure merged cells in the row
            foreach (var cellsToMerge in row.MergedCellsList)
            {
                // CellsToMerge example is "B2:D2"
                xlSheet.Range(cellsToMerge).Row(1).Merge();
            }

            if (row.Cells.Count != 0)
            {
                if (row.StartLocation is not null && row.EndLocation is not null)
                {
                    var xlRow = xlSheet.Row(row.Cells.First().Location.Y);
                    if (row.Height is not null)
                    {
                        xlRow.Height = (double)row.Height;
                    }

                    var xlRowRange = xlSheet.Range(row.StartLocation.Y, row.StartLocation.X, row.EndLocation.Y,
                                                   row.EndLocation.X);
                    xlRowRange.Style.Font.SetFontColor(XLColor.FromColor(row.ForeColor));
                    xlRowRange.Style.Fill.SetBackgroundColor(XLColor.FromColor(row.BackColor));

                    XLBorderStyleValues?outsideBorder = GetXlBorderLineStyle(row.OutsideBorder.LineStyle);

                    if (outsideBorder is not null)
                    {
                        xlRowRange.Style.Border.SetOutsideBorder((XLBorderStyleValues)outsideBorder);
                        xlRowRange.Style.Border.SetOutsideBorderColor(
                            XLColor.FromColor(row.OutsideBorder.Color));
                    }

                    // TODO: For Inside border, the row should be considered as Ranged (like Table). I persume it is not important for this phase
                }
                else
                {
                    var xlRow = xlSheet.Row(row.Cells.First().Location.Y);
                    if (row.Height is not null)
                    {
                        xlRow.Height = (double)row.Height;
                    }
                    xlRow.Style.Font.SetFontColor(XLColor.FromColor(row.ForeColor));
                    xlRow.Style.Fill.SetBackgroundColor(XLColor.FromColor(row.BackColor));
                    xlRow.Style.Border.SetOutsideBorder(XLBorderStyleValues.Dotted);
                    xlRow.Style.Border.SetInsideBorder(XLBorderStyleValues.Thick);
                    xlRow.Style.Border.SetTopBorder(XLBorderStyleValues.Thick);
                    xlRow.Style.Border.SetRightBorder(XLBorderStyleValues.DashDotDot);
                }
            }