Obtener el valor de cadena de la celda con o sin formato
Aspose.Cells proporciona un método Cell.getStringValue() que puede usarse para obtener el valor en cadena de la celda con o sin ningún formateo. Supón que tienes una celda con valor 0.012345 y la has formateado para mostrar solo dos lugares decimales. Entonces se mostrará como 0.01 en Excel. Puedes recuperar valores en cadena tanto como 0.01 como 0.012345 usando el método Cell.getStringValue(). Toma el enum CellValueFormatStrategy como parámetro con los siguientes valores
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.DisplayString
- CellValueFormatStrategy.None
El siguiente código de ejemplo explica el uso del método Cell.getStringValue().
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); |