Threaded Comments mit JavaScript via C++
Antwortkommentare
MS Excel 365 bietet eine Funktion zum Hinzufügen von Threaded-Kommentaren. Diese Kommentare fungieren als Unterhaltungen und können für Diskussionen verwendet werden. Die Kommentare enthalten nun eine Antwortbox, die Threaded-Konversationen ermöglicht. Die alten Kommentare werden in Excel 365 als Notizen bezeichnet. Der Screenshot unten zeigt, wie threaded Kommentare angezeigt werden, wenn sie in Excel geöffnet werden.

Threaded comments werden in älteren Versionen von Excel so angezeigt. Die folgenden Bilder wurden erstellt, indem die Beispieldatei in Excel 2016 geöffnet wurde.


Aspose.Cells bietet auch die Funktion zur Verwaltung von Threaded-Kommentaren.
Threaded-Kommentare hinzufügen
Threaded-Kommentar mit Excel hinzufügen
Um Threaded-Kommentare in Excel 365 hinzuzufügen, befolgen Sie die folgenden Schritte.
- Methode 1
- Klicken Sie auf die Registerkarte Überprüfen
- Klicken Sie auf die Schaltfläche Neuer Kommentar
- Dadurch wird ein Dialogfeld geöffnet, um Kommentare in der aktiven Zelle einzugeben.

- Methode 2
- Klicken Sie mit der rechten Maustaste auf die Zelle, in die Sie den Kommentar einfügen möchten.
- Klicken Sie auf die Option Neuer Kommentar.
- Dadurch wird ein Dialogfeld geöffnet, um Kommentare in der aktiven Zelle einzugeben.
Fügen Sie einen Kommentarfaden mit Aspose.Cells hinzu
Aspose.Cells bietet die Methode Comments.AddThreadedComment, um threaded comments hinzuzufügen. Die Methode Comments.AddThreadedComment akzeptiert die folgenden drei Parameter.
- Zellenname: Der Name der Zelle, in die der Kommentar eingefügt wird.
- Kommentartext: Der Text des Kommentars.
- ThreadedCommentAuthor: Der Verfasser des Kommentars
Das folgende Codebeispiel zeigt die Verwendung der Methode Comments.AddThreadedComment, um einen thread-spezifischen Kommentar in Zelle A1 hinzuzufügen. Bitte beachten Sie die Ausgabedatei, die durch den Code erstellt wird, zur Referenz.
Beispielcode
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - Add Threaded Comment</title>
</head>
<body>
<h1>Add Threaded Comment Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
// Create a new workbook
const workbook = new Workbook();
// Add Author
const authorIndex = workbook.worksheets.threadedCommentAuthors.add("Aspose Test", "", "");
const author = workbook.worksheets.threadedCommentAuthors.get(authorIndex);
// Add Threaded Comment to cell A1 in the first worksheet
const worksheet = workbook.worksheets.get(0);
worksheet.comments.addThreadedComment("A1", "Test Threaded Comment", author);
// Save the modified workbook and provide download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'AddThreadedComments_out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Threaded comment added successfully! Click the download link to get the file.</p>';
});
</script>
</html>
Lese kommentierte Fäden
Lese kommentierte Fäden mit Excel
Um kommentierte Fäden in Excel zu lesen, fahren Sie einfach mit der Maus über die Zelle, die Kommentare enthält, um die Kommentare anzuzeigen. Die Ansicht der Kommentare wird der Darstellung im folgenden Bild ähneln.

Lese kommentierte Fäden mit Aspose.Cells
Aspose.Cells bietet die Methode Comments.threadedComments zum Abrufen von kommentierten Fäden für die angegebene Spalte. Die Methode Comments.threadedComments akzeptiert den Spaltennamen als Parameter und gibt die ThreadedCommentCollection zurück. Sie können über die ThreadedCommentCollection iterieren, um die Kommentare anzuzeigen.
Das folgende Beispiel zeigt das Lesen von Kommentaren aus Spalte A1 durch Laden der Beispiel-Excel-Datei. Bitte sehen Sie die durch den Code generierte Konsolenausgabe zur Referenz an.
Beispielcode
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Threaded Comments Example</title>
</head>
<body>
<h1>Threaded Comments Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, Worksheet, Cell } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet
const worksheet = workbook.worksheets.get(0);
// Get Threaded Comments for cell A1
const threadedComments = worksheet.comments.threadedComments("A1");
const count = threadedComments.count;
let html = '<h2>Threaded Comments</h2>';
if (count === 0) {
html += '<p>No threaded comments found for A1.</p>';
} else {
html += '<ul>';
for (let i = 0; i < count; i++) {
const comment = threadedComments.get(i);
const notes = comment.notes;
const authorName = comment.author.name;
html += `<li><strong>Author:</strong> ${authorName} <br/><strong>Comment:</strong> ${notes}</li>`;
}
html += '</ul>';
}
resultDiv.innerHTML = html;
});
</script>
</html>
Konsolenausgabe
Comment: Test Threaded Comment
Author: Aspose Test
Lese Erstellungszeitpunkt von kommentierten Fäden
Aspose.Cells bietet die Methode Comments.threadedComments, um thread-spezifische Kommentare für die angegebene Spalte abzurufen. Die Methode Comments.threadedComments akzeptiert den Spaltennamen als Parameter und gibt die ThreadedCommentCollection zurück. Sie können die ThreadedCommentCollection durchlaufen und die ThreadedComment.createdTime-Eigenschaft verwenden.
Das folgende Beispiel zeigt das Lesen des Erstellungszeitpunkts von kommentierten Fäden durch Laden der Beispiel-Excel-Datei. Bitte sehen Sie die durch den Code generierte Konsolenausgabe zur Referenz an.
Beispielcode
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Threaded Comments Example</title>
</head>
<body>
<h1>Threaded Comments Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, Worksheet, Cell } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
const downloadLink = document.getElementById('downloadLink');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
// No try-catch: allow errors to propagate for testing
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Loads the workbook from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet
const worksheet = workbook.worksheets.get(0);
// Get Threaded Comments for cell A1
const threadedComments = worksheet.comments.threadedComments("A1");
const count = threadedComments.count;
let html = '<h2>Threaded Comments (Cell A1)</h2>';
if (count === 0) {
html += '<p>No threaded comments found in cell A1.</p>';
} else {
html += '<ul>';
for (let i = 0; i < count; i++) {
const comment = threadedComments.get(i);
const notes = comment.notes;
const authorName = comment.author.name;
const createdTime = comment.createdTime;
console.log("Comment: " + notes);
console.log("Author: " + authorName);
console.log("Created Time: " + createdTime);
html += `<li><strong>Author:</strong> ${authorName} <br/><strong>Created:</strong> ${createdTime} <br/><strong>Comment:</strong> ${notes}</li>`;
}
html += '</ul>';
}
resultDiv.innerHTML = html;
// No file modifications or save in this example; hide download link
downloadLink.style.display = 'none';
});
</script>
</html>
Konsolenausgabe
Comment: Test Threaded Comment
Author: Aspose Test
Created Time: 5/15/2019 12:46:23 PM
Kommentare bearbeiten
Bearbeiten Sie kommentierte Kommentare mit Excel
Um einen kommentierten Kommentar in Excel zu bearbeiten, klicken Sie auf den Bearbeiten-Link im Kommentar wie im folgenden Bild gezeigt.

Threaded-Kommentar bearbeiten mit Aspose.Cells
Aspose.Cells bietet die Methode Comments.threadedComments, um thread-spezifische Kommentare für die angegebene Spalte abzurufen. Die Methode Comments.threadedComments akzeptiert den Spaltennamen als Parameter und gibt die ThreadedCommentCollection zurück. Sie können den gewünschten Kommentar in der ThreadedCommentCollection aktualisieren und die Arbeitsmappe speichern.
Das folgende Beispiel zeigt die Bearbeitung des ersten verschachtelten Kommentars in Spalte A1, indem die Beispiel-Excel-Datei geladen wird. Bitte sehen Sie sich die Ausgabe-Excel-Datei an, die vom Code generiert wurde und den aktualisierten Kommentar zur Referenz zeigt.
Beispielcode
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Edit Threaded Comments Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
const resultDiv = document.getElementById('result');
if (!fileInput.files.length) {
resultDiv.innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiating a Workbook object by opening the Excel file from the file input
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access first worksheet
const worksheet = workbook.worksheets.get(0);
// Get Threaded Comment from cell A1
const comment = worksheet.comments.threadedComments("A1").get(0);
// Update the threaded comment notes
comment.notes = "Updated Comment";
// Save the modified Excel file
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'EditThreadedComments.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Edited Excel File';
resultDiv.innerHTML = '<p style="color: green;">Threaded comment updated successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>
Threaded-Kommentare entfernen
Threaded-Kommentare mit Excel entfernen
Um Threaded-Kommentare in Excel zu entfernen, klicken Sie mit der rechten Maustaste auf die Zelle mit den Kommentaren und wählen Sie die Option Kommentar löschen, wie im folgenden Bild gezeigt.
