public void Append() { var doc = new WorkbookDocument(); doc.Count.ShouldEqual(0); var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); var b = new MarkdownCell(); doc.AppendCell(b); TestEntryLinkage(doc, b, 2, a, b, a, null); var c = new MarkdownCell(); doc.AppendCell(c); TestEntryLinkage(doc, c, 3, a, c, b, null); var d = new MarkdownCell(); doc.AppendCell(d); TestEntryLinkage(doc, d, 4, a, d, c, null); TestEntryLinkage(doc, a, 4, a, d, null, b); TestEntryLinkage(doc, b, 4, a, d, a, c); TestEntryLinkage(doc, c, 4, a, d, b, d); TestEntryLinkage(doc, d, 4, a, d, c, null); }
static WorkbookDocument ParseText(string text) { var document = new WorkbookDocument(); document.Read(new StringReader(text)); return(document); }
public void InsertBefore() { var doc = new WorkbookDocument(); // [a] var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); // [b, a] var b = new MarkdownCell(); doc.InsertCellBefore(a, b); TestEntryLinkage(doc, b, 2, b, a, null, a); // [b, c, a] var c = new MarkdownCell(); doc.InsertCellBefore(a, c); TestEntryLinkage(doc, c, 3, b, a, b, a); // [b, d, c, a] var d = new MarkdownCell(); doc.InsertCellBefore(c, d); TestEntryLinkage(doc, d, 4, b, a, b, c); // [b, d, c, a] TestEntryLinkage(doc, b, 4, b, a, null, d); TestEntryLinkage(doc, d, 4, b, a, b, c); TestEntryLinkage(doc, c, 4, b, a, d, a); TestEntryLinkage(doc, a, 4, b, a, c, null); }
public void InsertAfter() { var doc = new WorkbookDocument(); // [a] var a = new MarkdownCell(); doc.AppendCell(a); TestEntryLinkage(doc, a, 1, a, a, null, null); // [a, b] var b = new MarkdownCell(); doc.InsertCellAfter(a, b); TestEntryLinkage(doc, b, 2, a, b, a, null); // [a, c, b] var c = new MarkdownCell(); doc.InsertCellAfter(a, c); TestEntryLinkage(doc, c, 3, a, b, a, b); // [a, c, d, b] var d = new MarkdownCell(); doc.InsertCellAfter(c, d); TestEntryLinkage(doc, d, 4, a, b, c, b); // [a, c, d, b] TestEntryLinkage(doc, a, 4, a, b, null, c); TestEntryLinkage(doc, c, 4, a, b, a, d); TestEntryLinkage(doc, d, 4, a, b, c, b); TestEntryLinkage(doc, b, 4, a, b, d, null); }
public void Enumerate() { var doc = new WorkbookDocument(); doc.GetEnumerator().MoveNext().ShouldBeFalse(); doc.AppendCell(new CodeCell("x", "a")); doc.AppendCell(new CodeCell("x", "b")); doc.AppendCell(new CodeCell("x", "c")); doc.AppendCell(new CodeCell("x", "d")); doc.Select(e => e.Buffer.Value).ToArray().ShouldEqual(new [] { "a", "b", "c", "d" }); }
static void TestEntryLinkage(WorkbookDocument document, Cell newEntry, int expectedCount, Cell expectedFirstEntry, Cell expectedLastEntry, Cell expectedPreviousEntry, Cell expectedNextEntry) { newEntry.Document.ShouldEqual(document); document.Count.ShouldEqual(expectedCount); if (expectedFirstEntry == null) { document.FirstCell.ShouldBeNull(); } else { document.FirstCell.ShouldEqual(expectedFirstEntry); } if (expectedLastEntry == null) { document.LastCell.ShouldBeNull(); } else { document.LastCell.ShouldEqual(expectedLastEntry); } if (expectedPreviousEntry == null) { newEntry.PreviousCell.ShouldBeNull(); } else { newEntry.PreviousCell.ShouldEqual(expectedPreviousEntry); } if (expectedNextEntry == null) { newEntry.NextCell.ShouldBeNull(); } else { newEntry.NextCell.ShouldEqual(expectedNextEntry); } }
public void Index() { var doc = new WorkbookDocument(); doc.AppendCell(new CodeCell("x", "a")); doc.AppendCell(new CodeCell("x", "b")); doc.AppendCell(new CodeCell("x", "c")); doc.AppendCell(new CodeCell("x", "d")); doc [0].Buffer.Value.ShouldEqual("a"); doc [1].Buffer.Value.ShouldEqual("b"); doc [2].Buffer.Value.ShouldEqual("c"); doc [3].Buffer.Value.ShouldEqual("d"); Assert.Throws <IndexOutOfRangeException> (() => Assert.IsNotNull(doc [-1])); Assert.Throws <IndexOutOfRangeException> (() => Assert.IsNotNull(doc [4])); }
internal override void OnDocumentRead() { try { this.workbook = WorkbookDocument.Parse(this.GetPackagePart().GetInputStream()).Workbook; Dictionary <string, XSSFSheet> dictionary = new Dictionary <string, XSSFSheet>(); foreach (POIXMLDocumentPart relation in this.GetRelations()) { if (relation is SharedStringsTable) { this.sharedStringSource = (SharedStringsTable)relation; } else if (relation is StylesTable) { this.stylesSource = (StylesTable)relation; } else if (relation is ThemesTable) { this.theme = (ThemesTable)relation; } else if (relation is CalculationChain) { this.calcChain = (CalculationChain)relation; } else if (relation is MapInfo) { this.mapInfo = (MapInfo)relation; } else if (relation is XSSFSheet) { dictionary.Add(relation.GetPackageRelationship().Id, (XSSFSheet)relation); } } if (this.stylesSource != null) { this.stylesSource.SetTheme(this.theme); } if (this.sharedStringSource == null) { this.sharedStringSource = (SharedStringsTable)this.CreateRelationship((POIXMLRelation)XSSFRelation.SHARED_STRINGS, (POIXMLFactory)XSSFFactory.GetInstance()); } this.sheets = new List <XSSFSheet>(dictionary.Count); foreach (CT_Sheet ctSheet in this.workbook.sheets.sheet) { XSSFSheet xssfSheet = dictionary[ctSheet.id]; if (xssfSheet == null) { XSSFWorkbook.logger.Log(5, (object)("Sheet with name " + ctSheet.name + " and r:id " + ctSheet.id + " was defined, but didn't exist in package, skipping")); } else { xssfSheet.sheet = ctSheet; xssfSheet.OnDocumentRead(); this.sheets.Add(xssfSheet); } } this.namedRanges = new List <XSSFName>(); if (!this.workbook.IsSetDefinedNames()) { return; } foreach (CT_DefinedName name in this.workbook.definedNames.definedName) { this.namedRanges.Add(new XSSFName(name, this)); } } catch (XmlException ex) { throw new POIXMLException((Exception)ex); } }
public void Remove() { var doc = new WorkbookDocument(); var a = new MarkdownCell(); doc.AppendCell(a); doc.Count.ShouldEqual(1); doc.RemoveCell(a); doc.Count.ShouldEqual(0); a.NextCell.ShouldBeNull(); a.PreviousCell.ShouldBeNull(); doc.FirstCell.ShouldBeNull(); doc.LastCell.ShouldBeNull(); var b = new MarkdownCell(); doc.AppendCell(a); doc.AppendCell(b); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(b); a.NextCell.ShouldEqual(b); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldEqual(a); doc.RemoveCell(b); doc.Count.ShouldEqual(1); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(a); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldBeNull(); a.NextCell.ShouldBeNull(); a.PreviousCell.ShouldBeNull(); doc.RemoveCell(a); var c = new MarkdownCell(); doc.AppendCell(a); doc.AppendCell(b); doc.AppendCell(c); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(c); a.NextCell.ShouldEqual(b); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldEqual(c); b.PreviousCell.ShouldEqual(a); c.NextCell.ShouldBeNull(); c.PreviousCell.ShouldEqual(b); doc.RemoveCell(b); doc.FirstCell.ShouldEqual(a); doc.LastCell.ShouldEqual(c); a.NextCell.ShouldEqual(c); a.PreviousCell.ShouldBeNull(); b.NextCell.ShouldBeNull(); b.PreviousCell.ShouldBeNull(); c.NextCell.ShouldBeNull(); c.PreviousCell.ShouldEqual(a); }