代码之家  ›  专栏  ›  技术社区  ›  Diodeus - James MacFarlane

从C生成Excel-如何制作对角线边框?

  •  3
  • Diodeus - James MacFarlane  · 技术社区  · 15 年前

    我使用C生成Excel电子表格,并使用 this library .我需要制作一个包含大X的单元格。客户端发送的示例使用左右对角线边界来完成此操作。

    我一直找不到正确的代码语法来以这种方式设置单元格的样式。怎么做到的?

    它应该是这样的:

    alt text http://preview.moveable.com/JM/ExcelBorders.gif

    1 回复  |  直到 15 年前
        1
  •  2
  •   manji    15 年前

    在从Excel保存的XML中,显示如下:

    <Style ss:ID="s22">
       <Borders>
        <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
        <Border ss:Position="DiagonalLeft" ss:LineStyle="Continuous" ss:Weight="1"/>
        ...
    

    我不知道这个库,但是我看到你可以用 XmlStyle 类,特别设置 Border.Sides 财产:

    XmlStyle sBorder = new XmlStyle();
    sBorder.Border.Color = Color.Black;
    sBorder.Border.Weight = 1;
    sBorder.Border.LineStyle = Borderline.Continuous;
    sBorder.Border.Sides = BorderSides.DiagonalLeft; //<-- here where I'm not sure!
                                                     //(I can't access the docs
                                                     // right now to check that Enum)
    
    sheet[x, y].Style = sBorder;
    

    如果你没试过的话,这可能会有帮助。