Beispiel #1
0
        public FileView Apply(TabularDocument <T> document)
        {
            var sharedStrings = new List <string>();
            var styles        = new List <XlsxCellStyle> {
                new XlsxCellStyle(),
                new XlsxCellStyle()
                {
                    HorizontalAlignment = HorizontalAlignmentValues.Center
                },
                new XlsxCellStyle(),
            };

            var content = new XlsxFileContent {
                Properties = new XlsxProperties {
                    CreatedBy      = document.CreatedBy,
                    Created        = document.Created.GetValueOrDefault(DateTimeOffset.Now).LocalDateTime,
                    LastModifiedBy = document.LastModifiedBy,
                    LastModified   = document.LastModified.GetValueOrDefault(DateTimeOffset.Now).LocalDateTime
                },
                Worksheets = new[] {
                    new XlsxWorksheet {
                        Title     = document.Title,
                        ZoomScale = 100,
                        Layout    = new XlsxLayout {
                            Columns = document.Items.Select(x => new DocumentLayoutUnit(x.Size)),
                            Rows    = new DocumentLayoutUnit[0]
                        },
                        Data = new[] {
                            new XlsxSection(
                                document.Items.Select((x, i) => new XlsxCell {
                                Row        = 1,
                                Column     = i + 1,
                                StyleIndex = 1,
                                Data       = GetCellValue(i + 1, sharedStrings),
                            }),
                                document.Items.Select((x, i) => new XlsxCell {
                                Row        = 2,
                                Column     = i + 1,
                                StyleIndex = 1,
                                Data       = GetCellValue(x.Title, sharedStrings),
                            }),
                                document.Data.SelectMany((item, i) => document.Items.Select((x, j) => new XlsxCell {
                                Row        = i + 3,
                                Column     = j + 1,
                                StyleIndex = x.ByCenter ? 1 : 2,
                                Data       = GetCellValue(x.GetValue(item, i + 1), sharedStrings)
                            }))
                                )
                        }
                    }
                },
                SharedStrings = sharedStrings.ToArray(),
                Styles        = styles.ToArray(),
            };

            return(new XlsxFileView(document.Title, content));
        }
Beispiel #2
0
 public XlsxFileView(string name, XlsxFileContent content)
 {
     Name    = name;
     Content = content;
 }