コード例 #1
0
            /// <summary>
            /// When overridden in a derived class, writes a message to the listener you create in the derived class, followed by a line terminator.
            /// </summary>
            /// <param name="message">A message to write. </param>
            public override void WriteLine([CanBeNull] string?message)
            {
                _buffer += message;

                try
                {
                    if (IgnoredErrors.Any(err => err.Match(_buffer).Success))
                    {
                        return;
                    }

                    _errorCallback(_buffer);
                }
                finally
                {
                    _buffer = null;
                }
            }
コード例 #2
0
        private static void AddTablePart(WorksheetPart sheetPart, TableColumn[] columns, int rowCount, WorkbookPart workBookPart)
        {
            if (sheetPart == null)
            {
                throw new ArgumentNullException(nameof(sheetPart));
            }

            if (columns == null)
            {
                throw new ArgumentNullException(nameof(columns));
            }

            if (rowCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(rowCount));
            }

            if (workBookPart == null)
            {
                throw new ArgumentNullException(nameof(workBookPart));
            }

            var rangeReference = GetXlsTableRangeReference(columns.Length, rowCount);

            var ignoredErrors = new IgnoredErrors(
                new IgnoredError
            {
                NumberStoredAsText   = true,
                SequenceOfReferences = new ListValue <StringValue>
                {
                    InnerText = rangeReference
                }
            }
                );

            // Ignored errors must be added before table parts.
            sheetPart.Worksheet.Append(ignoredErrors);

            var tableDefinitionPart = sheetPart.AddNewPart <TableDefinitionPart>();
            var autoFilter          = new AutoFilter {
                Reference = rangeReference
            };
            var tableColumns = new TableColumns {
                Count = (uint)columns.Length
            };
            var styleInfo = new TableStyleInfo
            {
                Name              = "TableStyleMedium2",
                ShowFirstColumn   = false,
                ShowLastColumn    = false,
                ShowRowStripes    = true,
                ShowColumnStripes = false
            };

            var tableId = workBookPart.WorksheetParts
                          .Select(x => x.TableDefinitionParts.Where(y => y.Table != null)
                                  .Select(y => (uint)y.Table.Id).DefaultIfEmpty(0U).Max()).DefaultIfEmpty(0U).Max() + 1;

            var table =
                new DocumentFormat.OpenXml.Spreadsheet.Table(autoFilter, tableColumns, styleInfo)
            {
                Id             = tableId,
                Name           = "Table" + tableId,
                DisplayName    = "Table" + tableId,
                Reference      = rangeReference,
                TotalsRowShown = false
            };

            for (var i = 0; i < columns.Length; i++)
            {
                table.TableColumns.Append(
                    new DocumentFormat.OpenXml.Spreadsheet.TableColumn
                {
                    Id   = (uint)(i + 1),
                    Name = columns[i].ColumnName
                });
            }

            tableDefinitionPart.Table = table;

            var tableParts = new TableParts(
                new TablePart
            {
                Id = sheetPart.GetIdOfPart(tableDefinitionPart)
            }
                )
            {
                Count = 1U
            };

            sheetPart.Worksheet.Append(tableParts);
        }