//-------------------------------------------------------------------------- #region ** ctor public Sheet(XLSheet xlSheet) { // customize style FontSize = 14; FontFamily = new FontFamily("Arial"); Padding = new Thickness(0); // create grid to hold the sheet data Grid = new C1FlexGrid(); Grid.MergeManager = new ExcelMergeManager(); // create editable label used as a header var label = new EditableLabel(); Header = label; // create context menu for this sheet var ctxMenu = new SheetContextMenu(this); // if we have a sheet, get its name and load it into the grid if (xlSheet != null) { SheetName = xlSheet.Name; ExcelFilter.Load(xlSheet, this.Grid); Visibility = xlSheet.Visible ? Visibility.Visible : Visibility.Collapsed; } // keep track of changes to the sheet name label.TextChanged += label_TextChanged; }
/// <summary> /// Saves the current book into an XLSX stream. /// </summary> /// <param name="stream"></param> public void Save(Stream stream) { // create the book to save var book = new C1XLBook(); book.Sheets.Clear(); // no sheets if (Sheets.Count == 0) { var xlSheet = book.Sheets.Add("Sheet1"); ExcelFilter.Save(this, xlSheet); } else { // save each sheet foreach (var sheet in Sheets) { var xlSheet = book.Sheets.Add(sheet.SheetName); ExcelFilter.Save(sheet.Grid, xlSheet); } } // save the book book.Save(stream, C1.WPF.Excel.FileFormat.OpenXml); }