Load or Import CSV file with Formulas

Contents
[ ]

The following code illustrates how you can load as well as import a CSV file with formulas. You can use any CSV file. For illustration purpose, we use the simple csv file which contains this data. As you see it contains a formula.

 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");

The code first loads the CSV file, then import it again at cell D4. Finally, it saves the workbook object in XSLX format. The output XLSX file looks like this. As you see cell C3 and F4 contain formula and its result 800.

todo:image_alt_text