コード例 #1
0
        public static void Run()
        {
            using (var stream = new FileStream($"{nameof(MultipleSheet)}.xlsx", FileMode.Create, FileAccess.Write))
                using (var xlsxWriter = new XlsxWriter(stream))
                {
                    var whiteFont      = new XlsxFont("Segoe UI", 9, Color.White, bold: true);
                    var blueFill       = new XlsxFill(Color.FromArgb(0, 0x45, 0x86));
                    var yellowFill     = new XlsxFill(Color.FromArgb(0xff, 0xff, 0x88));
                    var headerStyle    = new XlsxStyle(whiteFont, blueFill, XlsxBorder.None, XlsxNumberFormat.General, XlsxAlignment.Default);
                    var highlightStyle = XlsxStyle.Default.With(yellowFill);
                    var dateStyle      = XlsxStyle.Default.With(XlsxNumberFormat.ShortDateTime);

                    xlsxWriter
                    .BeginWorksheet("Sheet&'<1>\"", splitColumn: 1, splitRow: 2, columns: new [] { XlsxColumn.Unformatted(count: 2), XlsxColumn.Formatted(width: 20) })
                    .SetDefaultStyle(headerStyle)
                    .BeginRow().Write("Col<1>").Write("Col2").Write("Col&3")
                    .BeginRow().Write().Write("Sub2").Write("Sub3")
                    .SetDefaultStyle(XlsxStyle.Default)
                    .BeginRow().Write("Row3").Write(42).WriteFormula("B3*10", highlightStyle)
                    .BeginRow().Write("Row4").SkipColumns(1).Write(new DateTime(2020, 5, 6, 18, 27, 0), dateStyle)
                    .SkipRows(2)
                    .BeginRow().Write("Row7", XlsxStyle.Default.With(XlsxBorder.Around(new XlsxBorder.Line(Color.DeepPink, XlsxBorder.Style.Dashed))), columnSpan: 2).Write(3.14159265359)
                    .SetAutoFilter(1, 1, xlsxWriter.CurrentRowNumber, 3)
                    .BeginWorksheet("Sheet2", splitColumn: 1, splitRow: 1)
                    .BeginRow().Write("Lorem ipsum dolor sit amet,")
                    .BeginRow().Write("consectetur adipiscing elit,")
                    .BeginRow().Write("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
                    .SetAutoFilter(1, 1, xlsxWriter.CurrentRowNumber, 1);
                }
        }
コード例 #2
0
        public static void Run()
        {
            using (var stream = new FileStream($"{nameof(Border)}.xlsx", FileMode.Create, FileAccess.Write))
                using (var xlsxWriter = new XlsxWriter(stream))
                {
                    var leftBorderStyle     = XlsxStyle.Default.With(new XlsxBorder(left: new XlsxBorder.Line(Color.DeepPink, XlsxBorder.Style.Thin)));
                    var allBorderStyle      = XlsxStyle.Default.With(XlsxBorder.Around(new XlsxBorder.Line(Color.CornflowerBlue, XlsxBorder.Style.Dashed)));
                    var diagonalBorderStyle = XlsxStyle.Default.With(
                        new XlsxBorder(diagonal: new XlsxBorder.Line(Color.Red, XlsxBorder.Style.Dotted), diagonalDown: true, diagonalUp: true));

                    xlsxWriter
                    .BeginWorksheet("Sheet1")
                    .SkipRows(1)
                    .BeginRow(height: 50).SkipColumns(1).Write("B1", leftBorderStyle).SkipColumns(1).Write("D1", allBorderStyle).Write("E1", diagonalBorderStyle)
                    .BeginRow().SkipColumns(1).Write("B2", leftBorderStyle).SkipColumns(1).Write("D2", allBorderStyle).Write("E2", diagonalBorderStyle)
                    .BeginRow().SkipColumns(1).Write(leftBorderStyle).SkipColumns(1).Write(allBorderStyle).Write(diagonalBorderStyle);
                }
        }
コード例 #3
0
ファイル: Simple.cs プロジェクト: salvois/LargeXlsx
        public static void Run()
        {
            using (var stream = new FileStream($"{nameof(Simple)}.xlsx", FileMode.Create, FileAccess.Write))
                using (var xlsxWriter = new XlsxWriter(stream))
                {
                    var headerStyle = new XlsxStyle(
                        new XlsxFont("Segoe UI", 9, Color.White, bold: true),
                        new XlsxFill(Color.FromArgb(0, 0x45, 0x86)),
                        XlsxStyle.Default.Border,
                        XlsxStyle.Default.NumberFormat,
                        XlsxAlignment.Default);
                    var highlightStyle = XlsxStyle.Default.With(new XlsxFill(Color.FromArgb(0xff, 0xff, 0x88)));
                    var dateStyle      = XlsxStyle.Default.With(XlsxNumberFormat.ShortDateTime);
                    var borderedStyle  = highlightStyle.With(XlsxBorder.Around(new XlsxBorder.Line(Color.DeepPink, XlsxBorder.Style.Dashed)));

                    xlsxWriter
                    .BeginWorksheet("Sheet 1", columns: new[] { XlsxColumn.Unformatted(count: 2), XlsxColumn.Formatted(width: 20) })
                    .SetDefaultStyle(headerStyle)
                    .BeginRow().AddMergedCell(2, 1).Write("Col1").Write("Top2").Write("Top3")
                    .BeginRow().Write().Write("Col2").Write("Col3")
                    .SetDefaultStyle(XlsxStyle.Default)
                    .BeginRow().Write("Row3").Write(42).WriteFormula(
                        $"{xlsxWriter.GetRelativeColumnName(-1)}{xlsxWriter.CurrentRowNumber}*10", highlightStyle)
                    .BeginRow().Write("Row4").SkipColumns(1).Write(new DateTime(2020, 5, 6, 18, 27, 0), dateStyle)
                    .SkipRows(2)
                    .BeginRow().Write("Row7", borderedStyle, columnSpan: 2).Write(3.14159265359)
                    .BeginRow().Write("Bold").Write().Write("Be bold", XlsxStyle.Default.With(XlsxFont.Default.WithBold()))
                    .BeginRow().Write("Italic").Write().Write("Be italic", XlsxStyle.Default.With(XlsxFont.Default.WithItalic()))
                    .BeginRow().Write("Strike").Write().Write("Be struck", XlsxStyle.Default.With(XlsxFont.Default.WithStrike()))
                    .BeginRow().Write("Underline").Write().Write("Single", XlsxStyle.Default.With(XlsxFont.Default.WithUnderline()))
                    .BeginRow().Write("Underline").Write().Write("Double", XlsxStyle.Default.With(XlsxFont.Default.WithUnderline(XlsxFont.Underline.Double)))
                    .BeginRow().Write("Underline").Write().Write("SingleAccounting", XlsxStyle.Default.With(XlsxFont.Default.WithUnderline(XlsxFont.Underline.SingleAccounting)))
                    .BeginRow().Write("Underline").Write().Write("DoubleAccounting", XlsxStyle.Default.With(XlsxFont.Default.WithUnderline(XlsxFont.Underline.DoubleAccounting)))
                    .SetAutoFilter(2, 1, xlsxWriter.CurrentRowNumber - 1, 3);
                }
        }