Показать сообщение отдельно
Старый 19.05.2022, 11:59   #3  
DesparioN is offline
DesparioN
Участник
 
84 / 15 (1) ++
Регистрация: 21.10.2014
Пытался сделать по аналогии с уже существующим методом по коррекции шрифта

X++:
public void setNamedRangeBorder(Bookmark _bookmark, int _top = 1, int _left = 1, int _right = 1,
                                int _bottom = 1)
{
    DocumentFormat.OpenXml.Spreadsheet.TopBorder                topBorder,
                                                                newTopBorder;
    DocumentFormat.OpenXml.Spreadsheet.LeftBorder               leftBorder,
                                                                newleftBorder;
    DocumentFormat.OpenXml.Spreadsheet.RightBorder              rightBorder,
                                                                newrightBorder;
    DocumentFormat.OpenXml.Spreadsheet.BottomBorder             bottomBorder,
                                                                newBottomBorder;
    DocumentFormat.OpenXml.Spreadsheet.Border                   border,
                                                                newBorder;
    DocumentFormat.OpenXml.Spreadsheet.Borders                  borders;
    DocumentFormat.OpenXml.Spreadsheet.CellFormats              formats;
    DocumentFormat.OpenXml.Spreadsheet.CellFormat               format,
                                                                newFormat;
    DocumentFormat.OpenXml.Spreadsheet.Cell                     cell;
    DocumentFormat.OpenXml.OpenXmlElementList                   elementList;
    System.Collections.IEnumerator                              enumerator;

    int         fromRow;
    int         fromCol;
    int         toRow;
    int         toCol;

    int         styleIdx;
    int         borderIdx;
    int         curIdx;
    str         worksheetName;
    container   con;


    if(!this.definedNames().exists([_bookmark, #localSheetIdUndefined]))
    {
        throw error(strFmt("@GLS64283", _bookmark));
    }

    con = this.parseBookmark(_bookmark);

    worksheetName = conPeek(con, 1);
    fromRow       = conPeek(con, 2);
    fromCol       = conPeek(con, 3);
    toRow         = conPeek(con, 4);
    toCol         = conPeek(con, 5);

    if(templateMode)
    {
        cell = this.getWorksheet(worksheetName, true).rowTemplate(fromRow).cell(fromCol).cell();
        styleIdx = this.getWorksheet(worksheetName, true).rowTemplate(fromRow).cell(fromCol).styleIndex();
    }
    else
    {
        cell     = this.getWorksheet(worksheetName, true).row(fromRow).cell(fromCol).cell();
        styleIdx = this.getWorksheet(worksheetName, true).row(fromRow).cell(fromCol).styleIndex();
    }

    format      = this.getCellXfById(styleIdx);
    borderIdx   = OXML_RU::getUInt32Value(format.get_BorderId());

    stylesPart  = workbookPart.get_WorkbookStylesPart();
    styleSheet  = stylesPart.get_Stylesheet();
    borders     = styleSheet.get_Borders();
    elementList = borders.get_ChildElements();
    enumerator  = elementList.GetEnumerator();

    while(enumerator.MoveNext())
    {
        border = enumerator.get_Current();

        if(curIdx == borderIdx)
        {
            break;
        }

        curIdx++;
    }

    topBorder       = border.get_TopBorder();
    leftBorder      = border.get_LeftBorder();
    rightBorder     = border.get_RightBorder();
    bottomBorder    = border.get_BottomBorder();

    newTopBorder        = topBorder.Clone();
    newleftBorder       = leftBorder.Clone();
    newrightBorder      = rightBorder.Clone();
    newBottomBorder     = bottomBorder.Clone();

    newTopBorder.set_Style(OXML_RU::setInt32Value(_top));
    newLeftBorder.set_Style(OXML_RU::setInt32Value(_left));
    newRightBorder.set_Style(OXML_RU::setInt32Value(_right));
    newBottomBorder.set_Style(OXML_RU::setInt32Value(_bottom));

    newBorder = border.Clone();

    newBorder.set_TopBorder(newTopBorder);
    newBorder.set_LeftBorder(newLeftBorder);
    newBorder.set_RightBorder(newRightBorder);
    newBorder.set_BottomBorder(newBottomBorder);

    OXML_RU::appendChild(borders, newBorder);

    newFormat   = format.Clone();
    newFormat.set_BorderId(borders.get_Count());

    borders.set_Count(OXML_RU::setUInt32Value(OXML_RU::getUInt32Value(borders.get_Count()) + 1));

    formats = styleSheet.get_CellFormats();
    OXML_RU::appendChild(formats, newFormat);
    cell.set_StyleIndex(formats.get_Count());
    formats.set_Count(OXML_RU::setUInt32Value(OXML_RU::getUInt32Value(formats.get_Count()) + 1));