Comentarios en hilo con JavaScript vía C++
Comentarios enhebrados
MS Excel 365 proporciona una característica para agregar comentarios enhebrados. Estos comentarios funcionan como conversaciones y se pueden utilizar para discusiones. Los comentarios ahora vienen con un cuadro de respuesta que permite conversaciones enhebradas. Los comentarios antiguos se llaman Notas en Excel 365. La captura de pantalla a continuación muestra cómo se muestran los comentarios enhebrados cuando se abren en Excel.

Los comentarios enhebrados se muestran así en versiones anteriores de Excel. Las siguientes imágenes se han tomado al abrir el archivo de muestra en Excel 2016.


Aspose.Cells también proporciona la función para administrar comentarios enhebrados.
Agregar comentarios enhebrados
Agregar comentario en hilo con Excel
Para agregar comentarios en hilo en Excel 365, siga los siguientes pasos.
- Método 1
- Haga clic en la pestaña Revisar
- Haga clic en el botón Nuevo Comentario
- Esto abrirá un diálogo para ingresar comentarios en la celda activa.

- Método 2
- Haga clic derecho en la celda donde quiera insertar el comentario.
- Haga clic en la opción Nuevo Comentario
- Esto abrirá un diálogo para ingresar comentarios en la celda activa.
Agregar comentario en hilo usando Aspose.Cells
Aspose.Cells proporciona el método Comments.AddThreadedComment para agregar comentarios en hilo. El método Comments.AddThreadedComment acepta los siguientes tres parámetros.
- Nombre de la celda: El nombre de la celda donde se insertará el comentario.
- Texto del comentario: El texto del comentario.
- ThreadedCommentAuthor: El autor del comentario
El siguiente ejemplo de código demuestra el uso del método Comments.AddThreadedComment para agregar un comentario en hilo a la celda A1. Consulta el archivo Excel de salida generado por el código para referencia.
Código de muestra
<!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>
Leer comentarios en hilo
Leer comentarios en hilo con Excel
Para leer comentarios en hilo en Excel, simplemente coloque el mouse sobre la celda que contiene comentarios para ver los comentarios. La vista de los comentarios se verá como en la siguiente imagen.

Leer comentarios en hilo usando Aspose.Cells
Aspose.Cells proporciona el método Comments.threadedComments para recuperar los comentarios en hilo para la columna especificada. El método Comments.threadedComments acepta el nombre de la columna como parámetro y devuelve el ThreadedCommentCollection. Puedes iterar sobre el ThreadedCommentCollection para ver los comentarios.
El siguiente ejemplo demuestra la lectura de comentarios desde la columna A1 cargando el Archivo de Excel de muestra. Por favor, revisa la salida en la consola generada por el código para referencia.
Código de muestra
<!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>
Salida de la consola
Comment: Test Threaded Comment
Author: Aspose Test
Leer el Tiempo de Creación de comentarios en hilo
Aspose.Cells proporciona el método Comments.threadedComments para recuperar los comentarios en hilo para la columna especificada. El método Comments.threadedComments acepta el nombre de la columna como parámetro y devuelve el ThreadedCommentCollection. Puedes iterar sobre el ThreadedCommentCollection y usar la propiedad ThreadedComment.createdTime.
El siguiente ejemplo demuestra la lectura del tiempo de creación de comentarios en hilo cargando el Archivo de Excel de muestra. Por favor, revisa la salida en la consola generada por el código para referencia.
Código de muestra
<!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>
Salida de la consola
Comment: Test Threaded Comment
Author: Aspose Test
Created Time: 5/15/2019 12:46:23 PM
Editar Comentarios en Hilo
Editar comentario en hilo con Excel
Para editar un comentario en hilo en Excel, haz clic en el enlace Editar en el comentario según se muestra en la siguiente imagen.

Editar comentario en hilo usando Aspose.Cells
Aspose.Cells proporciona el método Comments.threadedComments para recuperar los comentarios en hilo de la columna especificada. El método Comments.threadedComments acepta el nombre de la columna como parámetro y devuelve el ThreadedCommentCollection. Puedes actualizar el comentario requerido en el ThreadedCommentCollection y guardar el libro de trabajo.
El siguiente ejemplo demuestra cómo editar el primer comentario en hilo en la columna A1 cargando el archivo de Excel de muestra. Consulta el archivo de Excel generado por el código, que muestra el comentario actualizado para referencia.
Código de muestra
<!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>
Eliminar Comentarios en Hilo
Eliminar comentarios en hilo con Excel
Para eliminar comentarios en hilo en Excel, haz clic derecho en la celda que contiene los comentarios y selecciona la opción Eliminar Comentario como se muestra en la siguiente imagen.
