Encontrar la posición absoluta de una forma dentro de la hoja de cálculo con JavaScript vía C++
Contents
[
Hide
]
A veces, necesitas conocer la posición absoluta de una forma en una hoja de cálculo. Aspose.Cells for JavaScript vía C++ proporciona las propiedades Shape.leftToCorner y Shape.topToCorner para este propósito. Estas propiedades devuelven la posición absoluta de la forma en píxeles.
El siguiente código de ejemplo muestra la posición absoluta de la primera forma en la hoja de cálculo en píxeles. El código de ejemplo muestra la siguiente salida en la consola:
Absolute Position of this Shape is (320 , 183)<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - Shape Position</title>
</head>
<body>
<h1>Get Shape Absolute Position</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, Utils } = 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();
// Load the sample Excel file inside the workbook object
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access the first worksheet
const worksheet = workbook.worksheets.get(0);
// Access the first shape inside the worksheet
const shape = worksheet.shapes.get(0);
// Displays the absolute position of the shape
const left = shape.leftToCorner;
const top = shape.topToCorner;
const message = `Absolute Position of this Shape is (${left} , ${top})`;
console.log(message);
resultDiv.innerHTML = `<p>${message}</p>`;
});
</script>
</html>