Zellenzeichenfolgenwert mit und ohne Formatierung abrufen
Aspose.Cells stellt eine Methode Cell.getStringValue() bereit, die verwendet werden kann, um den String-Wert der Zelle mit oder ohne Formatierung abzurufen. Angenommen, Sie haben eine Zelle mit dem Wert 0.012345 und haben diese so formatiert, dass nur zwei Dezimalstellen angezeigt werden. In Excel wird sie dann als 0.01 angezeigt. Sie können String-Werte sowohl als 0.01 als auch als 0.012345 mit der Methode Cell.getStringValue() abrufen. Sie akzeptiert den CellValueFormatStrategy-enum als Parameter, der die folgenden Werte hat.
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.DisplayString
- CellValueFormatStrategy.None
Der folgende Beispielcode erklärt die Verwendung der Cell.getStringValue()-Methode.
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); |