2017-07-28 16 views
1

セル用の罫線付きのExcelシート用のスタイルシートを作成していますが、境界線が2つ以上ない限り動作します。しかし、3番目の境界線を追加するとExcelを開くとxmlにエラーが発生することがわかりますが、3番目の境界線には左右の境界線があるときだけ表示されます。それがちょうど上端と下端にあるときは問題ありません。c#openxmlはスタイルシートの境界線エラーを訂正します

境界線のインデックス2にのみエラーが発生するのはなぜですか、境界線が左右にある場合のみですか?

私は以下の私のスタイルシート法のための完全なコードを入れますが、私はトラブルを抱えている具体的な部分はここにある:

以下
   //this is the border index 2 (third border) 
       new DocumentFormat.OpenXml.Spreadsheet.Border( 

        //error is caused by this section 
        //if I leave the right and left border out there is no error              
        //also no error if this whole border is border index 0 or 1 
        new DocumentFormat.OpenXml.Spreadsheet.RightBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DocumentFormat.OpenXml.Spreadsheet.LeftBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        // end section where error is caused 

        //top and bottom borders work just fine 
        new DocumentFormat.OpenXml.Spreadsheet.TopBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DocumentFormat.OpenXml.Spreadsheet.BottomBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DiagonalBorder() 
       )//, 

は、スタイルシート

private Stylesheet GenerateStyleSheet() 
    { 
     return new Stylesheet(


      new DocumentFormat.OpenXml.Spreadsheet.Fonts(
       new DocumentFormat.OpenXml.Spreadsheet.Font(                // Index 0 - The default font. 
        new FontSize() { Val = 11 }, 
        new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, 
        new FontName() { Val = "Calibri" }), 
       new DocumentFormat.OpenXml.Spreadsheet.Font(                // Index 1 - The bold font. 
        new Bold(), 
        new FontSize() { Val = 11 }, 
        new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "FFFFFF" } }, 
        new FontName() { Val = "Calibri" }), 
       new DocumentFormat.OpenXml.Spreadsheet.Font(                // Index 2 - The Italic font. 
        new Italic(), 
        new FontSize() { Val = 11 }, 
        new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, 
        new FontName() { Val = "Calibri" }), 
       new DocumentFormat.OpenXml.Spreadsheet.Font(                // Index 3 - The Times Roman font. with 16 size 
        new FontSize() { Val = 16 }, 
        new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, 
        new FontName() { Val = "Times New Roman" }) 
      ), 
      new Fills(
       new DocumentFormat.OpenXml.Spreadsheet.Fill(               // Index 0 - The default fill. 
        new DocumentFormat.OpenXml.Spreadsheet.PatternFill() { PatternType = PatternValues.None }), 
       new DocumentFormat.OpenXml.Spreadsheet.Fill(               // Index 0 - The default fill. 
        new DocumentFormat.OpenXml.Spreadsheet.PatternFill() { PatternType = PatternValues.None }), 
       new DocumentFormat.OpenXml.Spreadsheet.Fill(               // Index 2 - The gray fill. 
        new DocumentFormat.OpenXml.Spreadsheet.PatternFill(
         new DocumentFormat.OpenXml.Spreadsheet.ForegroundColor() { Rgb = new HexBinaryValue() { Value = "0000FF" } } 
        ) 
        { PatternType = PatternValues.Solid }) 
      ), 
      new DocumentFormat.OpenXml.Spreadsheet.Borders(
       new DocumentFormat.OpenXml.Spreadsheet.Border(              // Index 0 - The default border. 
        new DocumentFormat.OpenXml.Spreadsheet.LeftBorder(), 
        new DocumentFormat.OpenXml.Spreadsheet.RightBorder(), 
        new DocumentFormat.OpenXml.Spreadsheet.TopBorder(), 
        new DocumentFormat.OpenXml.Spreadsheet.BottomBorder(), 
        new DiagonalBorder()), 
       new DocumentFormat.OpenXml.Spreadsheet.Border(              // Index 1 - Applies a Left, Right, Top, Bottom border to a cell 
        new DocumentFormat.OpenXml.Spreadsheet.TopBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thin }, 
        new DocumentFormat.OpenXml.Spreadsheet.BottomBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DiagonalBorder() 
       ), 
       new DocumentFormat.OpenXml.Spreadsheet.Border(              // Index 1 - Applies a Left, Right, Top, Bottom border to a cell 
        new DocumentFormat.OpenXml.Spreadsheet.RightBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DocumentFormat.OpenXml.Spreadsheet.LeftBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DocumentFormat.OpenXml.Spreadsheet.TopBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DocumentFormat.OpenXml.Spreadsheet.BottomBorder(
         new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
        ) 
        { Style = BorderStyleValues.Thick }, 
        new DiagonalBorder() 
       )//, 
       //new DocumentFormat.OpenXml.Spreadsheet.Border(              // Index 1 - Applies a Left, Right, Top, Bottom border to a cell 
       // new DocumentFormat.OpenXml.Spreadsheet.TopBorder(
       //  new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
       // ) 
       // { Style = BorderStyleValues.Thick }, 
       // new DocumentFormat.OpenXml.Spreadsheet.BottomBorder(
       //  new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
       // ) 
       // { Style = BorderStyleValues.Thick }, 
       // new DocumentFormat.OpenXml.Spreadsheet.RightBorder(
       //  new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
       // ) 
       // { Style = BorderStyleValues.Thick }, 
       // new DiagonalBorder() 
       //) 

      ), 
      new CellFormats(
      //new CellFormat() { FontId = 1, FillId = 1, BorderId = 0 }//debug 



      new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 },       // Index 0 - The default cell style. If a cell does not have a style index applied it will use this style combination instead 
      new CellFormat(
       new Alignment() 
       { Horizontal = HorizontalAlignmentValues.Center, Vertical = VerticalAlignmentValues.Center } 
       ) 
      { FontId = 1, FillId = 2, BorderId = 0, ApplyFont = true } 
      ), 
      new CellFormat(
       new Alignment() 
       { 
        Horizontal = HorizontalAlignmentValues.Right, 
        Vertical = VerticalAlignmentValues.Bottom 
       } 
       ) 
       { 
        FontId = 0, FillId = 1, BorderId = 0 
       }, 
      new CellFormat(
       new Alignment() 
       { 
        Horizontal = HorizontalAlignmentValues.Right, 
        Vertical = VerticalAlignmentValues.Bottom 
       } 
      ) 
      { 
       FontId = 1, FillId = 0, BorderId = 2 
      } 
     ); // return 
    } 
を生成するための私の完全なコードです

答えて

1

境界要素はシーケンスとして定義されているため、明示的な順序があります。 LeftBorderはそうあなたは自分のコード内での順序を逆にする必要がRightBorderを来ています

new DocumentFormat.OpenXml.Spreadsheet.LeftBorder(
    new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
) 
{ Style = BorderStyleValues.Thick }, 
new DocumentFormat.OpenXml.Spreadsheet.RightBorder(
    new DocumentFormat.OpenXml.Spreadsheet.Color() { Auto = true } 
) 
{ Style = BorderStyleValues.Thick }, 
関連する問題