예제 #1
0
        public Book(string filename)
        {
            using var stream   = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using var document = SpreadsheetDocument.Open(stream, isEditable: false);
            var sweetDoc = new Bonn.Document(document);

            foreach (var it in sweetDoc.Sheets)
            {
                var columnLanguages = new Dictionary <int, string>();

                var sheet = new Sheet()
                {
                    Name = it.Name ?? ""
                };
                Sheets.Add(sheet);

                foreach (var cell in it.Cells())
                {
                    sheet.Set(cell.position, cell.value);
                }
            }
        }
예제 #2
0
        public void ToXlsx(string filename)
        {
            using var document = SpreadsheetDocument.Create(filename, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook);
            var excel = new Bonn.Document(document);

            foreach (var it in Sheets)
            {
                var sheet = excel.CreateSheet(it.Name);

                for (int i = 0; i < it.Rows.Count; ++i)
                {
                    var row = it.Rows[i];
                    for (int j = 0; j < row.Cells.Count; ++j)
                    {
                        var cell     = row.Cells[j];
                        var position = new Bonn.CellReference((uint)(j + 1), (uint)(i + 1));
                        sheet.SetCellValue(position, cell);
                    }
                }
            }

            document.Save();
        }