Node.jsとC++を使用してページ設定の拡大縮小率を計算する。
Contents
[
Hide
]
Fit to n page(s) wide by m tallオプションを利用したページ設定の拡大縮小率は、Microsoft Excelが計算します。同じ値はSheetRender.getPageScale()プロパティを使用して取得できます。このプロパティはパーセンテージに変換可能な倍精度浮動小数点値を返します。例:0.5なら拡大縮小率は50%。
次のサンプルコードは、SheetRender.getPageScale() プロパティを使用してページ設定のスケーリングファクターを計算する方法を示しています。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Loads the workbook which contains hidden external links
const workbook = new AsposeCells.Workbook(filePath);
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Put some data in these cells
worksheet.getCells().get("A4").putValue("Test");
worksheet.getCells().get("S4").putValue("Test");
// Set paper size
worksheet.getPageSetup().setPaperSize(AsposeCells.PaperSizeType.PaperA4);
// Set fit to pages wide as 1
worksheet.getPageSetup().setFitToPagesWide(1);
// Calculate page scale via sheet render
const sr = new AsposeCells.SheetRender(worksheet, new AsposeCells.ImageOrPrintOptions());
// Convert page scale double value to percentage
const strPageScale = (sr.getPageScale() * 100).toFixed(0) + "%";
// Write the page scale value
console.log(strPageScale);