protected override void CreatingSubWriters() { //如未指定模板Excel或模板Excel if (_book == null) { _book = _isXSSF ? (IWorkbook) new XSSFWorkbook() : new HSSFWorkbook(); // WorkbookFactory.Create(new MemoryStream()); } //记录模板的Sheet List <string> sheetnames = new List <string>(); for (int i = 0; i < _book.NumberOfSheets; i++) { sheetnames.Add(_book.GetSheetName(i)); } _allTempleteSheets = sheetnames.ToArray(); foreach (var sheet in ProductRule.Sheets) { ISheet exSheet = _book.GetSheet(sheet.Name) ?? _book.CreateSheet(sheet.Name); SheetWriter writer = new SheetWriter(exSheet, sheet, this); if (!sheet.IsDynamic) { Components.Add(writer); } else { exSheet.IsSelected = false; foreach (var dSheet in writer.GetDynamics()) { ISheet newSheet = exSheet.CopySheet(dSheet.NameRule); Components.Add(new SheetWriter(newSheet, dSheet, this)); } } } }
public SheetEnumerator(SheetWriter writer) { _sheet = writer.Entity as Sheet; _writer = writer; _dynamicObject = writer._dynamicObject; _curIndex = -1; }
/// <summary> /// 获取SheetWriter /// </summary> /// <param name="sheetName">Sheet模板名称(非动态Sheet或动态Sheet产生的模板Sheet)</param> /// <returns></returns> public SheetWriter GetSheetWriter(string sheetName) { SheetWriter tmpWriter = null; foreach (var writer in Components) { tmpWriter = writer as SheetWriter; if (tmpWriter != null && tmpWriter.Entity is Sheet) { Sheet sheet = tmpWriter.Entity as Sheet; if (sheet != null && (sheet.Name ?? "").Equals(sheetName)) { break; } } } return(tmpWriter); }
public SheetEnumerable(SheetWriter writer) { _writer = writer; }