Arbeiten mit Tischen in OneNote
Extrahieren des einfachen Textes aus der Tabelle des OneNote -Dokuments
ASSONE.NOTE FÜR .NET ermöglicht es Entwicklern, Text aus der gesamten Tabelle, einer Zeile oder einem bestimmten Zellelement zu extrahieren.
Aspose.Note für .NET bietet die Dokument Klasse an, die eine OneNote -Datei darstellt. Die Dokumentklasse enthält die GetChildnodes -Methode, die aufgerufen werden kann, um Tabellenknoten aus einem OneNote -Dokument zu extrahieren.
TABELLE -Text aus OneNote -Dokument erhalten
Dieses Beispiel funktioniert wie folgt:
- Erstellen Sie ein Objekt der Dokumentklasse.
- Rufen Sie die GetChildnodes -Methode der Dokumentklasse an.
- Rufen Sie eine Liste von Tabellenknoten ab.
- Rufen Sie den LINQ-basierten Code an, um Text zu extrahieren
- Zeigen Sie den Text auf dem Ausgangsbildschirm an.
Das folgende Codebeispiel zeigt, wie man Tabellentext von einem OneNote -Dokument abruft.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tables();
3
4// Load the document into Aspose.Note.
5Document document = new Document(dataDir + "Sample1.one");
6
7// Get a list of table nodes
8IList<Table> nodes = document.GetChildNodes<Table>();
9
10// Set table count
11int tblCount = 0;
12
13foreach (Table table in nodes)
14{
15 tblCount++;
16 Console.WriteLine("table # " + tblCount);
17
18 // Retrieve text
19 string text = string.Join(Environment.NewLine, table.GetChildNodes<RichText>().Select(e => e.Text)) + Environment.NewLine;
20 // Print text on the output screen
21 Console.WriteLine(text);
22}
Holen Sie sich Zeilentext aus einer Tabelle in einem OneNote -Dokument
Dieses Beispiel funktioniert wie folgt:
- Erstellen Sie ein Objekt der Dokumentklasse.
- Filtern Sie eine Liste von Tabellenknoten heraus.
- durch Tischreihen iterieren.
- Rufen Sie den LINQ-basierten Code an, um Text zu extrahieren.
- Zeigen Sie den Text auf dem Ausgangsbildschirm an.
Das folgende Codebeispiel zeigt, wie Zeilentext aus einer Tabelle in einem OneNote -Dokument extrahiert werden.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tables();
3
4// Load the document into Aspose.Note.
5Document document = new Document(dataDir + "Sample1.one");
6
7// Get a list of table nodes
8IList<Table> nodes = document.GetChildNodes<Table>();
9
10// Set row count
11int rowCount = 0;
12
13foreach (Table table in nodes)
14{
15 // Iterate through table rows
16 foreach (TableRow row in table)
17 {
18 rowCount++;
19 // Retrieve text
20 string text = string.Join(Environment.NewLine, row.GetChildNodes<RichText>().Select(e => e.Text)) + Environment.NewLine;
21 // Print text on the output screen
22 Console.WriteLine(text);
23 }
24}
Holen Sie sich den Zelltext aus einer Zeile in einer Tabelle
Dieses Beispiel funktioniert wie folgt:
- Erstellen Sie ein Objekt der Dokumentklasse.
- Filtern Sie eine Liste von Tabellenknoten heraus.
- durch die Tischreihen iterieren.
- Filtern Sie eine Liste von Zellknoten aus jeder Zeile heraus.
- durch die Zeilenzellen iterieren.
- Rufen Sie den LINQ-basierten Code an, um Text zu extrahieren.
- Zeigen Sie den Text auf dem Ausgangsbildschirm an.
Das folgende Codebeispiel zeigt, wie Zelltext aus einer Zeile der Tabelle abgerufen werden.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tables();
3
4// Load the document into Aspose.Note.
5Document document = new Document(dataDir + "Sample1.one");
6
7// Get a list of table nodes
8IList<Table> nodes = document.GetChildNodes<Table>();
9
10foreach (Table table in nodes)
11{
12 // Iterate through table rows
13 foreach (TableRow row in table)
14 {
15 // Get list of TableCell nodes
16 IList<TableCell> cellNodes = row.GetChildNodes<TableCell>();
17 // Iterate through table cells
18 foreach (TableCell cell in cellNodes)
19 {
20 // Retrieve text
21 string text = string.Join(Environment.NewLine, cell.GetChildNodes<RichText>().Select(e => e.Text)) + Environment.NewLine;
22 // Print text on the output screen
23 Console.WriteLine(text);
24 }
25 }
26}
Fügen Sie eine Tabelle in OneNote -Dokument ein
Mit Aspose.Note für .NET -APIs können Entwickler eine Tabelle an der jeweiligen Knotenposition einfügen. Dieser Artikel soll Ihnen zeigen, wie Sie programmatisch eine Tabelle in OneNote -Dokument erstellen.
Aspose.Note für .NET bietet die Dokument Klasse an, die eine OneNote -Datei darstellt. Entwickler können den Inhalt unter TableCell -Knoten, Tabellenzellen zum Tablerow Knoten, Tabelle Zeile zum Tabelle Knoten anhängen. Später konnten sie die Tabelle unter Umrissung Knoten, Umrisselement zum Umriss Knoten, Umriss auf Seite Knoten und dann eine Seite zum Dokumentknoten anhängen. Es basiert alles auf der Aspose.Note Dom -Struktur.
Das folgende Codebeispiel zeigt, wie Sie eine Tabelle in ein OneNote -Dokument einfügen.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tables();
3
4// Create an object of the Document class
5Document doc = new Document();
6// Initialize Page class object
7Aspose.Note.Page page = new Aspose.Note.Page(doc);
8
9// Initialize TableRow class object
10TableRow row1 = new TableRow(doc);
11// Initialize TableCell class objects
12TableCell cell11 = new TableCell(doc);
13TableCell cell12 = new TableCell(doc);
14TableCell cell13 = new TableCell(doc);
15
16// Append outline elements in the table cell
17cell11.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.1"));
18cell12.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.2"));
19cell13.AppendChildLast(GetOutlineElementWithText(doc, "cell_1.3"));
20// Table cells to rows
21row1.AppendChildLast(cell11);
22row1.AppendChildLast(cell12);
23row1.AppendChildLast(cell13);
24
25// Initialize TableRow class object
26TableRow row2 = new TableRow(doc);
27// initialize TableCell class objects
28TableCell cell21 = new TableCell(doc);
29TableCell cell22 = new TableCell(doc);
30TableCell cell23 = new TableCell(doc);
31
32// Append outline elements in the table cell
33cell21.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.1"));
34cell22.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.2"));
35cell23.AppendChildLast(GetOutlineElementWithText(doc, "cell_2.3"));
36
37// Append table cells to rows
38row2.AppendChildLast(cell21);
39row2.AppendChildLast(cell22);
40row2.AppendChildLast(cell23);
41
42// Initialize Table class object and set column widths
43Table table = new Table(doc)
44{
45 IsBordersVisible = true,
46 Columns = { new TableColumn { Width = 200 }, new TableColumn { Width = 200 }, new TableColumn { Width = 200 } }
47};
48// Append table rows to table
49table.AppendChildLast(row1);
50table.AppendChildLast(row2);
51
52// Initialize Outline object
53Outline outline = new Outline(doc);
54// Initialize OutlineElement object
55OutlineElement outlineElem = new OutlineElement(doc);
56// Add table to outline element node
57outlineElem.AppendChildLast(table);
58// Add outline element to outline
59outline.AppendChildLast(outlineElem);
60// Add outline to page node
61page.AppendChildLast(outline);
62// Add page to document node
63doc.AppendChildLast(page);
64dataDir = dataDir + "InsertTable_out.one";
65doc.Save(dataDir);
Erstellen Sie eine Tabelle mit gesperrten Spalten im OneNote -Dokument
Mit Aspose.Note für .NET -APIs können Entwickler eine Tabelle an der jeweiligen Knotenposition einfügen. Dieser Artikel soll Ihnen zeigen, wie Sie eine Tabelle mit einer gesperrten Spalte in OneNote -Dokument programmatisch erstellen. Aspose.Note für .NET bietet die Dokument Klasse an, die eine OneNote -Datei darstellt. Entwickler können den Inhalt unter TableCell -Knoten, Tabellenzellen zum Tablerow Knoten, Tabelle Zeile zum Tabelle Knoten anhängen. Die Lockedwidth -Eigenschaft der Tischklasse ermöglicht die Breite. Später konnten sie die Tabelle unter Umrissung Knoten, Umrisselement zum Umriss Knoten, Umriss zum Seite Knoten und dann eine Seite zum Dokumentknoten anhängen. Es basiert alles auf der Aspose.Note Dom -Struktur.
Das folgende Codebeispiel zeigt, wie eine Tabelle mit gesperrten Spalten in einem OneNote -Dokument eingefügt wird.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_Tables();
3
4// Create an object of the Document class
5Document doc = new Document();
6// Initialize Page class object
7Aspose.Note.Page page = new Aspose.Note.Page(doc);
8
9// Initialize TableRow class object
10TableRow row1 = new TableRow(doc);
11// Initialize TableCell class object and set text content
12TableCell cell11 = new TableCell(doc);
13cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
14row1.AppendChildLast(cell11);
15
16// Initialize TableRow class object
17TableRow row2 = new TableRow(doc);
18// Initialize TableCell class object and set text content
19TableCell cell21 = new TableCell(doc);
20cell21.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Long text with several words and spaces."));
21row2.AppendChildLast(cell21);
22
23// Initialize Table class object
24Table table = new Table(doc)
25{
26 IsBordersVisible = true,
27 Columns = { new TableColumn { Width = 70, LockedWidth = true } }
28};
29// Add rows
30table.AppendChildLast(row1);
31table.AppendChildLast(row2);
32
33Outline outline = new Outline(doc);
34OutlineElement outlineElem = new OutlineElement(doc);
35// Add table node
36outlineElem.AppendChildLast(table);
37// Add outline element node
38outline.AppendChildLast(outlineElem);
39// Add outline node
40page.AppendChildLast(outline);
41// Add page node
42doc.AppendChildLast(page);
43dataDir = dataDir + "CreateTableWithLockedColumns_out.one";
44doc.Save(dataDir);
GetOutlineElementWithText -Methode
1public static OutlineElement GetOutlineElementWithText(Document doc, string text)
2{
3 OutlineElement outlineElem = new OutlineElement(doc);
4 ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
5 outlineElem.AppendChildLast(new RichText(doc) { Text = text, ParagraphStyle = textStyle });
6 return outlineElem;
7}
Einstellen von Zellen Hintergrundfarbe
1// Create an object of the Document class
2Document doc = new Document();
3// Initialize Page class object
4Aspose.Note.Page page = new Aspose.Note.Page(doc);
5
6// Initialize TableRow class object
7TableRow row1 = new TableRow(doc);
8// Initialize TableCell class object and set text content
9TableCell cell11 = new TableCell(doc);
10cell11.AppendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text"));
11cell11.BackgroundColor = Color.Coral;
12row1.AppendChildLast(cell11);
Änderung des Stils einer Tabelle
1 private static void SetRowStyle(TableRow row, Color highlightColor, bool bold, bool italic)
2 {
3 foreach (var cell in row)
4 {
5 cell.BackgroundColor = highlightColor;
6
7 foreach (var node in cell.GetChildNodes<RichText>())
8 {
9 node.ParagraphStyle.IsBold = bold;
10 node.ParagraphStyle.IsItalic = italic;
11
12 foreach (var style in node.Styles)
13 {
14 style.IsBold = bold;
15 style.IsItalic = italic;
16 }
17 }
18 }
19 }
20
21 [STAThread]
22 public static void Main()
23 {
24 string dataDir = RunExamples.GetDataDir_Tables();
25
26 // Load the document into Aspose.Note.
27 Document document = new Document(dataDir + "ChangeTableStyleIn.one");
28
29 // Get a list of table nodes
30 IList<Table> nodes = document.GetChildNodes<Table>();
31
32 foreach (Table table in nodes)
33 {
34 SetRowStyle(table.First(), Color.DarkGray, true, true);
35
36 // Highlight first row after head.
37 var flag = false;
38 foreach (var row in table.Skip(1))
39 {
40 SetRowStyle(row, flag ? Color.LightGray : Color.Empty, false, false);
41
42 flag = !flag;
43 }
44 }
45
46 document.Save(Path.Combine(dataDir, "ChangeTableStyleOut.one"));
47 }