Carica o importa il file CSV con le formule
Contents
[
Hide
]
CSV contiene principalmente dati testuali e non contengono formule. Tuttavia, a volte capita che i file CSV contengano anche formule. Tali file CSV devono essere caricati impostando l’estensioneTxtLoadOptions.HasFormula comeVERO . Una volta impostata questa proprietàVERO, Aspose.Cells non considererà la formula come semplice testo. Saranno trattati come formula e il motore di calcolo della formula Aspose.Cells li elaborerà come al solito.
Il codice seguente illustra come caricare e importare un file CSV con formule. Puoi utilizzare qualsiasi file CSV. A scopo illustrativo, utilizziamo ilsemplice file csv che contiene questi dati. Come vedi contiene una formula.
300,500,=Sum(A1:B1)
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
TxtLoadOptions opts = new TxtLoadOptions(); | |
opts.Separator = ','; | |
opts.HasFormula = true; | |
// Load your CSV file with formulas in a Workbook object | |
Workbook workbook = new Workbook(dataDir + "sample.csv", opts); | |
// You can also import your CSV file like this | |
// The code below is importing CSV file starting from cell D4 | |
Worksheet worksheet = workbook.Worksheets[0]; | |
worksheet.Cells.ImportCSV(dataDir + "sample.csv", opts, 3, 3); | |
// Save your workbook in Xlsx format | |
workbook.Save(dataDir + "output_out.xlsx"); |
Il codice carica prima il file CSV, quindi lo importa nuovamente nella cella D4. Infine, salva l’oggetto cartella di lavoro in formato XSLX. Iloutput XLSX file Somiglia a questo. Come vedi le celle C3 e F4 contengono la formula e il suo risultato 800.
![]() |
---|