書式設定ありおよびなしでセル文字列の値を取得
Contents
[
Hide
]
Aspose.Cellsは、セルの文字列値をフォーマットの有無にかかわらず取得できるCell.getStringValue()メソッドを提供します。例えば、値0.012345のセルを小数点以下2桁にフォーマットすると、Excelでは0.01と表示されます。Cell.getStringValue()メソッドを用いて、0.01と0.012345の両方の値を取得できます。これは以下の列挙された値を持つCellValueFormatStrategy型のパラメータが必要です。
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.DisplayString
- CellValueFormatStrategy.None
以下のサンプルコードはCell.getStringValue()メソッドの使用例を説明しています。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AsposeCells = require("aspose.cells.node"); | |
const path = require("path"); | |
// The path to the documents directory. | |
const dataDir = path.join(__dirname, "data"); | |
// Create workbook | |
const workbook = new AsposeCells.Workbook(); | |
// Access first worksheet | |
const worksheet = workbook.getWorksheets().get(0); | |
// Access cell A1 | |
const cell = worksheet.getCells().get("A1"); | |
// Put value inside the cell | |
cell.putValue(0.012345); | |
// Format the cell that it should display 0.01 instead of 0.012345 | |
const style = cell.getStyle(); | |
style.setNumber(2); | |
cell.setStyle(style); | |
// Get string value as Cell Style | |
let value = cell.getStringValue(AsposeCells.CellValueFormatStrategy.CellStyle); | |
console.log(value); | |
// Get string value without any formatting | |
value = cell.getStringValue(AsposeCells.CellValueFormatStrategy.None); | |
console.log(value); |