Ottieni il valore di una stringa della cella con o senza formattazione
Aspose.Cells fornisce un metodo Cell.getStringValue() che può essere usato per ottenere il valore stringa della cella con o senza formattazione. Supponi di avere una cella con valore 0.012345 e di averla formattata per visualizzare solo due decimali. Verrà visualizzata come 0.01 in Excel. Puoi recuperare i valori stringa sia come 0.01 che come 0.012345 usando il metodo Cell.getStringValue(). Prende come parametro l’enumerazione CellValueFormatStrategy che ha i seguenti valori.
- CellValueFormatStrategy.CellStyle
- CellValueFormatStrategy.DisplayStyle
- CellValueFormatStrategy.DisplayString
- CellValueFormatStrategy.None
Il seguente esempio di codice spiega l’uso del metodo 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); |