Lectura y escritura CSV Formato de archivo

Posibles escenarios de uso

Microsoft Excel admite muchos formatos como XLS, XLSX, XLSM, XLSB, CSV, etc. Aspose.Cells también admite muchos de estos formatos. Este artículo explica cómo leer y escribir el archivo de Excel que tiene el formato CSV usando Aspose.Cells.

Lectura y escritura CSV Formato de archivo

El siguiente código de ejemplo carga elfuente CSV archivo y lee su celda A1 y luego copia su contenido a la celda C4 y lo guarda comoarchivo de salida CSV.

Código de muestra

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\");
//Output directory path
StringPtr outPath = new String("..\\Data\\Output\\");
//Path of input csv file
StringPtr srcReadWriteCSV = dirPath->StringAppend(new String(L"srcReadWriteCSV.csv"));
//Path of output csv file
StringPtr outReadWriteCSV = outPath->StringAppend(new String(L"outReadWriteCSV.csv"));
//Read source csv file
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(srcReadWriteCSV);
//Access first worksheet
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0);
//Access cell A1
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("A1"));
//Get the string value of cell A1
StringPtr strVal = cell->GetStringValue();
//Print the string value of cell A1
StringPtr cellValue = new String("Cell Value: ");
Console::WriteLine(cellValue->StringAppend(strVal));
//Access cell C4
cell = ws->GetICells()->GetObjectByIndex(new String("C4"));
//Put the string value of cell A1 into C4
intrusive_ptr<String> strValPtr = new String(strVal);
cell->PutValue(strValPtr);
//Save the workbook in csv format
wb->Save(outReadWriteCSV, SaveFormat_CSV);