Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Office Open for excel为百分比设置一个小数位数_C#_Excel_Openxml - Fatal编程技术网

C# Office Open for excel为百分比设置一个小数位数

C# Office Open for excel为百分比设置一个小数位数,c#,excel,openxml,C#,Excel,Openxml,我正在使用OPENXML创建excel文档,我想用“85.5%”这样的百分比格式显示百分比,小数点后一位。 我找不到任何合适的解决办法 下面是我创建样式表的函数 private Stylesheet GenerateStyleSheet(NumberingFormat nf2decimal) { return new Stylesheet( new Fonts( new Font(new FontSize() { V

我正在使用OPENXML创建excel文档,我想用“85.5%”这样的百分比格式显示百分比,小数点后一位。 我找不到任何合适的解决办法

下面是我创建样式表的函数

private Stylesheet GenerateStyleSheet(NumberingFormat nf2decimal)
    {
        return new Stylesheet(
            new Fonts(
                new Font(new FontSize() { Val = 11 }, new Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, new FontName() { Val = "Calibri" }),
                new Font(new Bold(), new FontSize() { Val = 12 }, new Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, new FontName() { Val = "Calibri" }),
                new Font(new Bold(), new FontSize() { Val = 11 }, new Color() { Rgb = new HexBinaryValue() { Value = "FCCB02" } }, new FontName() { Val = "Calibri" }),
                new Font(new Bold(), new FontSize() { Val = 11 }, new Color() { Rgb = new HexBinaryValue() { Value = "000000" } }, new FontName() { Val = "Calibri" }),
                new Font(new Italic(), new FontSize() { Val = 11 }, new Color() { Rgb = new HexBinaryValue() { Value = "008000" } }, new FontName() { Val = "Calibri" }),
                new Font(new Bold(), new FontSize() { Val = 14 }, new Color() { Rgb = new HexBinaryValue() { Value = "008000" } }, new FontName() { Val = "Calibri" })
            ),
            new Fills(
                new Fill(new PatternFill() { PatternType = PatternValues.None }),
                new Fill(new PatternFill() { PatternType = PatternValues.Gray125 }),
                new Fill(new PatternFill(new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "6E6E6E" } }) { PatternType = PatternValues.Solid }),
                new Fill(new PatternFill(new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "FFB3B3" } }) { PatternType = PatternValues.Solid }),
                new Fill(new PatternFill(new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "B3FFB3" } }) { PatternType = PatternValues.Solid }),
                new Fill(new PatternFill(new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "FFDB99" } }) { PatternType = PatternValues.Solid }),
                new Fill(new PatternFill(new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "EAEAEA" } }) { PatternType = PatternValues.Solid })
            ),
            new Borders(
                new Border(new LeftBorder(), new RightBorder(), new TopBorder(), new BottomBorder(), new DiagonalBorder()),
                new Border(new LeftBorder() { Style = BorderStyleValues.Thick }, new RightBorder() { Style = BorderStyleValues.Thick }, new TopBorder() { Style = BorderStyleValues.Thick }, new BottomBorder() { Style = BorderStyleValues.Thick }, new DiagonalBorder()),
                new Border(new LeftBorder() { Style = BorderStyleValues.Thin }, new RightBorder() { Style = BorderStyleValues.Thin }, new TopBorder() { Style = BorderStyleValues.Thin }, new BottomBorder() { Style = BorderStyleValues.Thin }, new DiagonalBorder())
                , new Border(new LeftBorder(), new RightBorder(), new TopBorder(), new BottomBorder(), new DiagonalBorder())
            ),

            new CellFormats(
            //0
                new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 },
            //1
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Center, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 1, FillId = 0, BorderId = 1, ApplyBorder = true, },
            //2
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 3, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true },
            //3
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 5, FillId = 6, BorderId = 2, ApplyBorder = true, ApplyFill = true },
            //4
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 2, FillId = 2, BorderId = 2, ApplyFill = true, ApplyBorder = true },
            //5
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Center, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 3, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true },
            //6
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 0, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 3 },
            //7
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 0, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 10 },
            //8
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 0, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 9 },
            //9
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 3, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 3 },
            //10
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 3, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 9 },
            //11
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 4, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 3 },
            //12
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 4, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 9 },
            //13
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 5, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 3 },
            //14
                new CellFormat(new Alignment() { WrapText = true }) { FontId = 4, FillId = 5, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = nf2decimal.NumberFormatId },
            //15
                new CellFormat(new Alignment() { Horizontal = HorizontalAlignmentValues.Left, Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 0, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true },
            //16
                new CellFormat(new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true }) { FontId = 0, FillId = 0, BorderId = 2, ApplyFill = false, ApplyBorder = true, ApplyNumberFormat = true, NumberFormatId = 3 }
            )

        ); // return
    }
有人能帮我吗