Bestimmung der absoluten Position einer Form innerhalb des Arbeitsblatts mit JavaScript via C++
Contents
[
Hide
]
Manchmal müssen Sie die absolute Position einer Form in einem Arbeitsblatt kennen. Aspose.Cells for JavaScript via C++ stellt hierfür die Eigenschaften Shape.leftToCorner und Shape.topToCorner bereit. Diese Eigenschaften geben die absolute Position der Form im Arbeitsblatt in Pixeln zurück.
Der folgende Beispielcode zeigt die absolute Position der ersten Form im Arbeitsblatt in Pixeln an. Der Beispielcode zeigt die folgende Konsolenausgabe:
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>