Laden oder Importieren von CSV Dateien mit Formeln
Der folgende Code zeigt, wie Sie eine CSV-Datei mit Formeln laden und importieren können. Sie können jede CSV-Datei verwenden. Zu Veranschaulichungszwecken verwenden wir die einfache CSV-Datei, die diese Daten enthält. Wie Sie sehen, enthält sie eine Formel.
300,500,=Sum(A1:B1)
// 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"); |
Der Code lädt zunächst die CSV-Datei, importiert sie dann erneut in die Zelle D4. Schließlich speichert er das Arbeitsmap-Objekt im XSLX-Format. Die Ausgabe-XLSX-Datei sieht so aus. Wie Sie sehen, enthalten die Zelle C3 und F4 eine Formel und ihr Ergebnis 800.
![]() |
---|